My script keeps timing out so I am hoping to make it run in the background. I submit a form to a page which says this: $url_to_grab = $_POST['url']; $page_count = $_POST['pagecount']; $shop_id = $_POST['shopid']; exec("php bg_script.php?url=$url_to_grab&page_count=$page_count&shop_id=$shop_id &"); PHP: Then in the backgound script it says this: $url_to_grab = $_GET['url']; $page_count = $_GET['pagecount']; $shop_id = $_GET['shopid']; PHP: and starts performing some stuff. But it doesn't. I guess I either have the exec command wrong (couldn't find ANYwhere how to pass variables) or the $_GET won't work. Any help would be appreciated, thank you. My gut feeling is that I'm miles off... Perhaps exec should have been system() BTW running PHP 4.3.1 on FreeBSD 4.8-STABLE
When you run a PHP script from the shell, the variables you pass to it are done a little different. You can find some info about it here: http://www.php.net/manual/en/features.commandline.php But what it basically comes down to is that variables are passed to the script as parameters. For example: php script.php var1 var2 var3 Then you will have an array of $argv with your different arguments.
I've changed it to: $url_to_grab = $_POST['url']; $page_count = $_POST['pagecount']; $shop_id = $_POST['shopid']; exec("php bg_script.php $url_to_grab $page_count $shop_id &"); PHP: Then in the backgound script it says this: $url_to_grab = $argv[0]; $page_count = $argv[1]; $shop_id = $argv[2]; PHP: It's pretty tough without any errors coming back at you to guess what's going on. Is it possible at all to run a php script like this if I don't know the absolute path to php.exe?
Well $argv[0] is going to be the name of the script itself... so use 1-3 instead. or print_r ($argv) within that script to verify. As far as the PHP path, it depends on the web server setup. If the PHP executable is within environment path for the web server "user" you don't need to know the path, otherwise you will.
Is there any way I can tell from the phpinfo command? I tried the most basic filewrite from the backgorund script to see if it's alive at all but it's not doing anything.
I'm going to wuss out and cut the process up in bits to avoid timing out. This exec thing is too much of a headache and I need a solution fast. Thanks for your assistance!