Jump to content

[SOLVED] Run external program and not wait for its completion


vcv

Recommended Posts

hello all, I have a problem that google has been unable to solve for me. I need a php script to run an external program and simply continue execution without waiting for its completion. Currently i am calling "system($cmd);" where that then runs a java program to create and send an xmlrpc request to the cluster that then performs calculations for at least an hour. What I would like is it to just call $cmd and not bother waitiing on it. thank you

Link to comment
Share on other sites

If your server is running linux ( it better be!! ) you can add this char '&' at the end of your command line and it will run the task in the background.

 

Also, remember to redirect all outputs to a log file or /dev/null or else the PHP script will have to wait for the programs output.

Link to comment
Share on other sites

thank you both for your replies. I had already tried the & but didnt route the output to /dev/null and doing so made it work like a charm :) . So for future posterity, my solution is:

system($cmd."  > /dev/null 2>&1 &");

 

I didnt try the fork but im sure that could work if i just didnt wait for the child. Thank you very much for ya'lls help!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.