Running a Php script continuously PHP Server Side Scripting forum at WebmasterWorld
 Welcome to WebmasterWorld Guest from 54.205.253.53 register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts, Subscribe to WebmasterWorld
 Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library : Charter : Moderators: coopster & jatar k

# PHP Server Side Scripting Forum

 Tweet
Running a Php script continuously
TravelSite

msg:1257824
3:04 pm on Feb 12, 2006 (gmt 0)

I have php and apache installed on my own local pc - making it act like a server - and need to run a php script continuously for long periods of time. This script makes constant use of a mysql database stored on my pc.

To run the script I enter [localhost...] - but after a few minutes the script times out. So I've adjusted the script so that after it has finished one iteration it does a page redirect - back to itself (so the script runs again). But after a fw minutes its times out again.

Could someone shed some light for me onto whats going on here - e.g. why it keeps stopping. Thanks.

jamesa

msg:1257825
3:19 pm on Feb 12, 2006 (gmt 0)

Probably cause your script is exceeding the "max_execution_time" which is usually 30 seconds by default. You can change this in your php.ini file. Better solution, though, might be running your script from the command line.

HTH

caspita

msg:1257826
3:25 pm on Feb 12, 2006 (gmt 0)

No need to modify your pnp.ini just for that, you can set the max_execution_time on the fly using ini_set(). But anyway I think appache has its own time out (about 5 mins?), but as said above, becacuse it is your local pc (server), you must be able to run it from the command line with with no restrictions, the timeout restrictions apply to web sessions only as so far I know.

PM me if you need more help.

TravelSite

msg:1257827
3:49 pm on Feb 12, 2006 (gmt 0)

Jamesa and Caspita - thanks for your help.

What do I enter to run it from the Run program?

Is all my php / mysql connections ok for this or do I need to change aspects of the code?

jamesa

msg:1257828
4:04 pm on Feb 12, 2006 (gmt 0)

Well in Unix it'd be:
php scriptname.php

might need the full path to php:
/path/to/php scriptname.php

On Windows it'd probably something like
C:\path\to\php scriptname.php

Now if you have anything in the query string, for example scriptname.php?id=1234&color=blue, that wouldn't work on the command line. Instead you can do this:

C:\path\to\php scriptname.php "1234" "blue"

and in the script:

<?

$id =$_SERVER["argv"][1];
$color =$_SERVER["argv"][2];

?>

TravelSite

msg:1257829
4:42 pm on Feb 12, 2006 (gmt 0)

Thanks - I've now got the script running fine and continuously using a big while loop :)

One last thing - how do I redirect from one script to another using the command line?

E.g. in my script I could have:
$url="Location: second-script.php?id=$id";

caspita

msg:1257830
5:08 pm on Feb 12, 2006 (gmt 0)

I don't think re-direct will work because what you are setting there are the headers for the browser/web server, etc. In the command line you are not using the browser nor the web sever at all. Instead you may want to check into some other php functions like exec, shell_exec, etc. This doc will show you more:

[us3.php.net...]

 Global Options: top home search open messages active posts  Tweet

 Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting