View Full Version : exec() and system() wait for script to complete!

Oct 10th, 2011, 01:17 AM
Hey guys i'm having a little trouble to get my script to work propperly

I'm using system() to run a bash script but the problem is that php waits for the script to complete before it can go any further.

The script takes a while to complete (it's an uploading script. It uploads files from my server to another server so the user is NOT uploading anything) so until the script is done, the page won't load.

Here's what's going on:

User goes onto page. Clicks upload button. This is a link to a php script/page which should display "Upload initiated." However instead it will NOT load (circle keeps turning). When I change the bash script to just echo Hello World it works fine but if I innitiate plowup (the application which does the uploading) it hangs.

Is there a way around this? I want the page to load and everything else to happen in the background.

Also a note is that everything DOES work, i just need the page to load and PHP not to time out (because I am sure it will if I wait longer than 30 sec)

Oct 10th, 2011, 04:10 AM
Launch it in to the background with & so it doesn't wait for the return value:

exec('./test.sh > /dev/null 2>&1 &');