Turquoise Rings - Mortgage - Charity - Car Credit - Mortgages uk

PDA

View Full Version : exec help required please


T0PS3O
Oct 28th 2004, 10:15 am
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 &");

Then in the backgound script it says this:

$url_to_grab = $_GET['url'];
$page_count = $_GET['pagecount'];
$shop_id = $_GET['shopid'];

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() :confused:

BTW running PHP 4.3.1 on FreeBSD 4.8-STABLE

digitalpoint
Oct 28th 2004, 10:23 am
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.

T0PS3O
Oct 28th 2004, 10:30 am
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 &");

Then in the backgound script it says this:


$url_to_grab = $argv[0];
$page_count = $argv[1];
$shop_id = $argv[2];


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?

digitalpoint
Oct 28th 2004, 10:33 am
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.

T0PS3O
Oct 28th 2004, 10:39 am
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.

digitalpoint
Oct 28th 2004, 10:54 am
I'm not sure... if it would tell anywhere, it probably would be there.

T0PS3O
Oct 29th 2004, 2:35 am
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!