Computing.Net > Forums > Web Development > Non stop reload of a page to server

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Non stop reload of a page to server

Reply to Message Icon

Name: Zolo
Date: November 5, 2009 at 23:58:27 Pacific
OS: Windows XP
CPU/Ram: 700mb
Subcategory: PHP
Comment:

I need to reload a php page to a server again and again continuously 24/7. I am running locallhost. I cant use timed reload like <META HTTP-EQUIV="Refresh" content="5;url=http://localhost/php_reloader.php> as this will introduce synchronization problems. I need to reload when the code executes to the end.

The following is what I have done but it stops after about 20minute. I think it runs out of memory. On the page reload1.php I have put the code:

<?php
//I have put my php code in this area. normal code that is working ok
bla...bla...bla in php!

//Now at the end of my bla.. bla... code I call (by include) the other page called //reload2.php like so;
include ("reload2.php"); //this includes relaod2.php
?>

//Now my trick is I have the same bla.bla.bla code on reload2.php and make it call relaod1.php as follows:

<?php
//I have put my php code in this area. normal that is code working ok
bla...bla...bla in php!

//Now at the end of my bla.. bla... code i call (by include) the other page called reload2.php
include ("reload1.php"); //this includes relaod1.php
?>

By doing this I hope to create an indefinite cycle of reload1.php calling reload2.php and then reload2.php calling back reload1.php. Perpetual machine? Yes!!! At the first it was working just for a few seconds. I realized I needed to change "resource limits" on the php configuration file (php.conf). I changed to below

max_execution_time = -1 ; Maximum execution time of each script, in seconds(30)
max_input_time = -1 ; Maximum amount of time each script may spend parsing ;request data(60)
memory_limit = -1 ; Maximum amount of memory a script may consume (16MB)

I changed the parameters above to -1 to make them limitless.(otherwise the default are the values show in brackets). This improved my perpetual machine to run from seconds to over fifteen minutes. But I don't want it to stop at all (unless i say so).

Windows Task Manager shows that PF (memory) usage fills up slowly until it matches that of the available RAM, and then the whole thing stops. This happens even when an I have put nothing in the code to echo to the browser.

Please help!
ZOLO



Sponsored Link
Ads by Google

Response Number 1
Name: Fist (by fmwap)
Date: November 6, 2009 at 00:35:46 Pacific
Reply:

Well, that is going to do exactly that - include itself forever until it eats up all your RAM.

The refresh must be done CLIENT side - you can't do it server-side with php. The best you could hope for is:

header("refresh:2;url=reload2.php");

But all that does, is nicely ask the browser to refresh to the given URL in 2 seconds - there's no guarantee that it will ever happen.

Other methods are the meta tag refresh you described, and a javascript refresh, but there's always going to be latency, the web server will delay the request if it's really busy - nothing you can do about it. HTTP is the wrong protocol for low latency communications.


0

Response Number 2
Name: Zolo
Date: November 6, 2009 at 04:34:24 Pacific
Reply:

Walaa! I got my perpetual machine running!! Thank you Fist for reminding me about Javascript.

All I needed was to call a Javascript function from my php like so...

<?php

echo "<SCRIPT LANGUAGE='javascript'>reloader();</SCRIPT>";

?>

And my javascript function being

<script type="text/javascript">
function reloader() {
setTimeout("location.reload(true);",100);
}

</script>

Of course my reloader() is still timed but I can call it from any part of my php block. That's what I wanted. I have run it none stop for more than an hour now and my memory is intact. Yes there is some latency but that's fine with me as I need to this to read a GPRS modem. Currently I can change the function timing to be able to read three cycles in a second. That's way too fast for my modem. (though my earlier solution could do 30Hz)

ZOLO


0

Response Number 3
Name: andrue
Date: November 7, 2009 at 21:36:17 Pacific
Reply:

ya........javascrip is the best solution for this.I used the same technique in one of our client project in
www.freelance4free.com
The above description is perfect soln for this.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Non stop reload of a page to server

non www version of my site www.computing.net/answers/webdevel/non-www-version-of-my-site/4165.html

HomePC serve pages to my work PC www.computing.net/answers/webdevel/homepc-serve-pages-to-my-work-pc/1505.html

How to show results of a survey www.computing.net/answers/webdevel/how-to-show-results-of-a-survey/622.html