1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

exec help required please

Discussion in 'PHP' started by T0PS3O, Oct 28, 2004.

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

    BTW running PHP 4.3.1 on FreeBSD 4.8-STABLE
     
    T0PS3O, Oct 28, 2004 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    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.
     
    digitalpoint, Oct 28, 2004 IP
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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?
     
    T0PS3O, Oct 28, 2004 IP
  4. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #4
    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.
     
    digitalpoint, Oct 28, 2004 IP
  5. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    T0PS3O, Oct 28, 2004 IP
  6. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #6
    I'm not sure... if it would tell anywhere, it probably would be there.
     
    digitalpoint, Oct 28, 2004 IP
  7. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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!
     
    T0PS3O, Oct 29, 2004 IP