I am trying to build a server where users can submit a query, and visualize the output. Till now everything is okay. I have seen that it is possible to run a workflow by command line using for example :
knime -nosplash -application org.knime.product.KNIME_BATCH_APPLICATION -workflowDir="workspace/workflow_name/"
I've seen that it exists a php function to run bash commands, called exec().
But when I use it, it doesn't seem to work well. Before using the command to run the workflow in php I have tested it in a simple terminal, it works well.
Do you have any idea or suggestion to solve my little problem ?
exec() is one of the risky functions you should only ever use in limited intranet contexts, and even there very sparingly. Given that it's both dangerously convenient and risky I believe you need to explicitly activate it in the php.ini - some generic PHP documentation should help you with that. I also imagine that you'll need to take care of memory allocation, since exec() normally won't trigger software of that magnitude. Finally, there might be an issue with the command-line syntax KNIME uses - it's been years since I touched this stuff, but there might be special characters in need of escaping involved. But again, that's something for PHP-specific support I cannot provide offhand, sorry. :-)
Thank you for your reply.
I will try to find a solution and post it here, I think that it can be usefull for other users.
Good luck! The amount of comments on http://php.net/manual/en/function.exec.php suggests it's quite a challenge. A "lessons learned" article would be helpful indeed, looking forward to that!
It seems that it is possible according to the link provided by Ergonomist, but it depends on the host operating system (windows or unix).
It is indeed possible to use the class COM and Run() function to create ajob which will be ran independently from the initial php script. This class is available on on window's php versions.
For unix, it seems possible to use nohup and exec(). I am still investigating to find a proper way to use it (as I am working on unix).
In all cases (windows or unix), Ergonomist says right about a character escape issue. For windows, it seems that ' ^ ' is the necessary to escape special characters seuch as ' " ' in :
knime -nosplash -application org.knime.product.KNIME_BATCH_APPLICATION -workflowDir="workflow/"
Getting back to you soon
I am still on this issue.
This time using exec() and nohup, I am able to run knime using the command line from the batch mode. But this time I am having a problem with Java Runtime Environment :
# A fatal error has been detected by the Java Runtime Environment:
# SIGSEGV (0xb) at pc=0x00007f5ecac4d4e9, pid=9123, tid=140080904931072
# JRE version: Java(TM) SE Runtime Environment (7.0_60-b19) (build 1.7.0_60-b19)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.60-b09 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libgdk-x11-2.0.so.0+0x6e4e9] gdk_window_enable_synchronized_configure+0x9
# Core dump written. Default location: /opt/lampp/htdocs/server/requests/29/core or core.9123
# An error report file with more information is saved as:
# If you would like to submit a bug report, please visit:
You might be able to find the log file attached.
Any idea ?
I finally succeed to fix this, the last post's problem seemed to be related to wrong use of the command line (arguments escaped ?).
Instead, I think that the following option should work on unix :
exec('ulimit -c unlimited; nohup /opt/lampp/htdocs/server/knime_2.9.2/knime -nosplash -application org.knime.product.KNIME_BATCH_APPLICATION -workflowDir="workflow/" --launcher.suppressErrors > process.out 2> process.err 0</dev/null &');
EDIT : It also require a folder named "knime-workspace/" in "/usr/sbin/", with all the permissions (rwx).
I know it has been a while since you were discussing this issue. I was reading your post recently and following through but I still have troubles with executing my knime project through command line and PhP. It is a Batch Executer error “IO error while loading the workflow”.
I cannot address the problem. in addition in your work flow directory, did you stop at Knime_project folder or did you proceed to “workflow.knime”?
You can specify your workflow in this manner:
MyWorkflow is the directory of your Knime project/workflow. (This usually contains directories of the nodes you used, as well as the workflow.knime file).
Hope this helps.
I am also trying to call a Knime workflow from PHP using exec(), however I am using Windows.
The path in the exec function below successfully invokes Knime when it is entered directly into the command line, but is not working when used with exec() in PHP. Note that the 'knime' at the beginning of the path is set to the path of the knime.exe file.
exec('knime -noexit -consolelog -application org.knime.product.KNIME_BATCH_APPLICATION -nosplash -reset -workflowDir="E:\www\apps\knime\Knime_CommandLine2"');
I have also tried using shell_exec() and system() in place of exec(), but have not been successful.
Does this post help you? https://stackoverflow.com/questions/20617458/php-exec-with-quotes#20617635