I have this exec command which runs just fine, but doesn’t free up the browser (ie. there is a php timeout issue, but the actual command continues to run):
exec("/usr/local/php53/bin/php csv.php $file $user > /dev/null");
When I run ps auxw I see these two running processes:
sh -c /usr/local/php53/bin/php csv.php /tmp/php9Pwu9e 294 >
/usr/local/php53/bin/php csv.php /tmp/php9Pwu9e 294
However, when I run the code below, the browser immediately is free, but the command doesn’t continue to run:
exec("/usr/local/php53/bin/php csv.php $file $user > /dev/null &");
When I run ps auxw I see one running process that dies after 16 seconds (and seems to eat up memory quickly and use a lot of CPU%):
/usr/local/php53/bin/php csv.php /tmp/php9Pwu9e 294
Then the process dies without having actually done anything. Not sure what the ampersand is doing that would cause this.
Also why does sh -c appear when no ampersand is present at the end? I feel that this may be indicative of something, but have no idea what.
EDIT:
Because this keeps cropping up as an answer,
I have also tried:
exec("/usr/local/php53/bin/php csv.php $file $user > /dev/null 2>&1 &");
Which demonstrates the same issue as mentioned above.
The code below, does run, but does NOT free up the browser.
exec("usr/local/php53/bin/php csv.php $file $user > /dev/null 2>&1");
The issue was much simpler than I had thought. The problem was the
$file(which was an uploaded file being stored in the/tmpdirectory) was not found. I’m not sure why, but I imagine it has something to do with the file being destroyed before the background process can get to it.The solution was to
move_uploaded_file()the file to a permanent location, and run the script with that file. That worked.