Welcome to WebmasterWorld Guest from 54.162.50.232

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Running a Php script continuously

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

Preferred Member

10+ Year Member

joined:June 11, 2003
posts:417
votes: 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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2002
posts:710
votes: 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

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

Full Member

10+ Year Member

joined:Dec 1, 2003
posts:311
votes: 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.

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

Preferred Member

10+ Year Member

joined:June 11, 2003
posts:417
votes: 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?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2002
posts:710
votes: 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];

?>
4:42 pm on Feb 12, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:June 11, 2003
posts:417
votes: 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";
header($url);

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

Full Member

10+ Year Member

joined:Dec 1, 2003
posts:311
votes: 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...]

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members