jumbo Posted July 3, 2012 Share Posted July 3, 2012 I'm trying to call a script to run in the background. The script is in a file called script1.php, and I'm calling it from a test page through the following code: <? exec("/usr/bin/php /home/myaccount/public_html/test/script1.php >/dev/null &"); ?> I took this code from someone on the internet. They claimed this is the way to do it. However nothing happens. The script is supposed to write in the database. If I run script1.php directly, it works fine. Is the syntax I'm using correct? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/265140-run-background-script/ Share on other sites More sharing options...
n1concepts Posted July 3, 2012 Share Posted July 3, 2012 Take a look at http://php.net/manual/en/function.exec.php which will provide examples to help you debug your syntax. Quote Link to comment https://forums.phpfreaks.com/topic/265140-run-background-script/#findComment-1358778 Share on other sites More sharing options...
Adam Posted July 3, 2012 Share Posted July 3, 2012 There's nothing wrong with the syntax. All you're doing is using the php binaries to execute the script, writing the output to nothingness (">/dev/null") and then telling the command to run in the background ("&"). I'm guessing there's a permissions issue or something along those lines, so I would add in the second parameter and remove the write to /dev/null so you can check the response. Quote Link to comment https://forums.phpfreaks.com/topic/265140-run-background-script/#findComment-1358794 Share on other sites More sharing options...
kicken Posted July 3, 2012 Share Posted July 3, 2012 You should redirect the stderr stream to dev null as well, using a line like this: exec("/usr/bin/php /home/myaccount/public_html/test/script1.php >/dev/null 2>&1 &"); Beyond that, make sure you have the correct path to your script1.php file, and also to the php executable. If you have SSH access to the server you can run the command which php to find out the path to the PHP binary. Quote Link to comment https://forums.phpfreaks.com/topic/265140-run-background-script/#findComment-1358833 Share on other sites More sharing options...
danlen Posted July 4, 2012 Share Posted July 4, 2012 Are you on a shared hosting system? I'm facing the same problem and have been pounding my head on the desk trying to find the magic combination. Unfortunately, I have just been informed by Myhosting.com that they are blocking "exec" on shared hosting servers. I'll need to move up to a VPS system in order to gain that functionality. The annoying thing is that I used "function_exists" to convince myself that the function was available. So, just because it's on the system, doesn't mean you can use it... Quote Link to comment https://forums.phpfreaks.com/topic/265140-run-background-script/#findComment-1359173 Share on other sites More sharing options...
Adam Posted July 4, 2012 Share Posted July 4, 2012 Are you on a shared hosting system? I'm facing the same problem and have been pounding my head on the desk trying to find the magic combination. Unfortunately, I have just been informed by Myhosting.com that they are blocking "exec" on shared hosting servers. I'll need to move up to a VPS system in order to gain that functionality. The annoying thing is that I used "function_exists" to convince myself that the function was available. So, just because it's on the system, doesn't mean you can use it... That's pretty much standard on a shared host. Quote Link to comment https://forums.phpfreaks.com/topic/265140-run-background-script/#findComment-1359181 Share on other sites More sharing options...
danlen Posted July 4, 2012 Share Posted July 4, 2012 Standard that is is blocked, or standard that no warning is issued? (At least it looks like no warning or error is issued...) Both? Quote Link to comment https://forums.phpfreaks.com/topic/265140-run-background-script/#findComment-1359188 Share on other sites More sharing options...
Adam Posted July 4, 2012 Share Posted July 4, 2012 Standard that it's blocked. You might not be seeing any errors because you have the display_errors config set to 0. Please open another thread if you want more help with that though. Quote Link to comment https://forums.phpfreaks.com/topic/265140-run-background-script/#findComment-1359189 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.