SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to run a UPDATE.PHP script that calls multiple .php files (it's for a CRON job - I don't want mess with multiple cron jobs).

    How would I do this? I obviously can't use headers.

    I thought of maybe the exec() function, but it seems to be for unix commands.

    Thanks again for the help!

  2. #2
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have two options here when using exec() if your host has the CGI version of PHP installed then you can use exec like this:

    exec( '/path/to/php/binary /path/to/script/to/run.php' );
    exec( '/path/to/php/binary /path/to/script2/to/run.php' );

    etc. or you can use the text based web browser to execute each script:

    exec( '/path/to/php/lynx -d tempFile http://www.domains.com/path/to/script/to/run.php' );
    exec( '/path/to/php/lynx -d tempFile http://www.domains.com/path/to/script/to/run.php' );

    I'm not to sure if it is -d tempFile you need or not, you would have to look it up, what it is supposed to do is tell lynx to send all output from the page to tempFile -if it doesn't and it sends output to the screen then the cron job will fail.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  3. #3
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Karl,

    I can seem to get it to work on my home machine running Windows. I know the path is correct because the task manager shows a "php" task for a few secs. But nothing happens!

    Is there any way to debug exec()? I'm having a hell of time trying to figure out what I'm doing wrong.

  4. #4
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:

    $var = `/path/to/php /path/to/file.php`

    $var should then contain the output of file.php.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  5. #5
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is it

    $var= "command"

    or

    $var= exec("command") ?


    On Linux, I finally got this to work by removing the " >> /dev/null " which I though was necessary?

    exec("lynx -dump http://domain.com/go.php"); //WORKS!
    exec("lynx -dump http://domain.com/go.php >> /dev/null"); //DOES NOT WORK


    The PHP binary method doesn't want to work on my Windows machine. My workaround has been calling IE:

    exec(' "C:\Program Files\Internet Explorer\IEXPLORE.EXE" http://127.0.0.1/db/go.php');

    This has the unsightly side effect of opening a new window for each exec(). It's really frustrating trying to figure out what's wrong when there are no error messages or output of any sort!

  6. #6
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $var = `command` (it's NOT the double or single-quote, it's the one next to "1" on your keyboard, people might know it as backtick.

    Using $var = `command` will return the output to $var while exec just goes and prints the output directly
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  7. #7
    SitePoint Enthusiast Jujubee's Avatar
    Join Date
    Mar 2001
    Location
    Canada
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, after hours and hours of digging, I've figured out that lynx won't run from within a script on my host. Backticks don't work either.

    It'll run if started by a cron job, but not from a PHP file. From what I've gathered, this is due to permissions. The PHP script runs lynx as user "nobody" and as such, Lynx doesn't like it (probably can't write/read the files it needs).

    So my only recourse was to call the CGI version of PHP which thankfully was already installed on my host.

    This is what I use inside my "update_daily.php":

    exec("/usr/bin/php -q /home/root/public_html/foo.php");

    (change "root" to your root dir - mine is my username)

    Thanks for the help, and hopefully some one will find a use for this.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •