August 21st, 2000, 08:18 PM
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?
August 22nd, 2000, 07:07 PM
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
August 22nd, 2000, 07:38 PM
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.
August 22nd, 2000, 07:54 PM
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).]