#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Nutley,NJ,USA
    Posts
    7
    Rep Power
    0
    Hi All.
    In order to run a php script - do I need to access it via a browser? Is there a way to write a php script and let it run from the shell in the background?



  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    London/UK
    Posts
    91
    Rep Power
    14
    Hi, this is not a problem if you've got php compiled as a CGI, you can then cron it or run it via the command line and if's its a big script (i.e. will take a while to complete) use set_time_limit(n) where n is a number in seconds (or '0' which is for ever) else it'll still timeout after 30 seconds (bt default php.ini settings)

    You'll need to add the shebang line @ the top before your opening php tag, something like #!/usr/bin/php

    I've used this succesfully *many* times, one noteable example was a script that took 3 days to complete (it was parsing 60 10MB files and doing various DB transactions)

    One could argue that PHP is not the best way to build backgrounding tasks, maybe perl or bash would be better, but hey if PHP is all you know, then it can do it

    hth

    Bealers

    ------------------
    http://back-end.org
  4. #3
  5. No Profile Picture
    Viper_SB
    Guest
    Devshed Newbie (0 - 499 posts)
    I had to do the same thing. What I came up with was a program that just retrived the file from the net, called "wget" just add a line like this to the cron.

    wget -b http://www.yoursite.com/yourpage.php3

    Note: It will download the page to your comp(and will NOT overight any files with the same name, will and a .1 and keep going. ie: myfile.php3 myfile.php3.1 myfile.php3.2) everytime it is run if you have it going once or more a day you will get a lot of files. Just and another line to the cron to remove it.

    ------------------
    Viper_SB
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    I use lynx myself (just another option)

    In the crontab just add:

    lynx -dump /path/to/some.php > /path/to/logs/some_log

    If there is any problem with some.php (db access, remote file access etc), it sends me an email. some_log isn't really necessary just a place to send any output such as an error situation that I failed to account for in the code... it gets overwritten each time so you don't have to worry about it getting huge.

    This works whether php is cgi or module.

    [This message has been edited by rod k (edited August 22, 2000).]

Similar Threads

  1. Replies: 2
    Last Post: August 18th, 2004, 10:45 PM
  2. How to see the Memory used by a PHP script?
    By Pardall in forum PHP Development
    Replies: 4
    Last Post: February 13th, 2004, 03:54 PM
  3. Replies: 4
    Last Post: January 28th, 2004, 08:29 AM
  4. MySQL "source" command in PHP
    By crackwombat in forum PHP Development
    Replies: 2
    Last Post: January 18th, 2004, 06:25 AM
  5. Passing string from PHP to Javascript
    By ka8oad in forum JavaScript Development
    Replies: 4
    Last Post: January 17th, 2004, 03:12 PM

IMN logo majestic logo threadwatch logo seochat tools logo