Alfred Posted November 22, 2010 Share Posted November 22, 2010 Hey, I'm not that familiar with PHP so maybe what I'm asking for is not even possible. I plan to establish a webserver that is connected to a RS232 device. I don't have any problems accessing the RS232 interface with a PHP-script, it's all working fine. Now I want the incoming data from the device being display on the servers webpage almost in realtime. When I say almost I mean that the client who is logged on to the website should be able to define the update rate of the incoming data. So here comes the problem, I need something like the java script setinterval() function that is working on the server-side and repeats the data request to the device in an infinite loop with the given time interval. I don't want to refresh the whole page as I will have to update about 20 sets of data within seconds! I found this code: http://phpclasses.chimit.nl/package/5544-PHP-Call-a-function-after-a-period-of-time.html it looks pretty promissing but I just can't make it working... As I said I'm a PHP-noob so I just put the code below on the start of my own code and provided the Timer.class.php file in my project folder. Could anyone explain how I could make the test function repeating endlessly on a 1sec basis using this code so I would get a screen full of "called"? So far I only get two "called" :-) Thanks! declare(ticks=100); function test () { print "<br>called"; } require_once 'Timers.class.php'; setTimeout('test', 110000000); setInterval('test', 10000000); [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/219476-php-repeating-interval-function/ Share on other sites More sharing options...
micah1701 Posted November 22, 2010 Share Posted November 22, 2010 what if you made a recursive function and had it sleep for x number of seconds before calling itself again. <?php function do_stuff(){ // do something sleep(20); // wait 20 seconds do_stuff(); // call this function again } ?> Link to comment https://forums.phpfreaks.com/topic/219476-php-repeating-interval-function/#findComment-1137983 Share on other sites More sharing options...
doni49 Posted November 22, 2010 Share Posted November 22, 2010 What will happen when there is more than one user logged on? Link to comment https://forums.phpfreaks.com/topic/219476-php-repeating-interval-function/#findComment-1137994 Share on other sites More sharing options...
Alfred Posted November 22, 2010 Author Share Posted November 22, 2010 @ micah1701: Does this really work? So the script would sleep for 20 seconds but would I still be able to us all buttons while the script is in sleep mode? How about this timer solution is this feasible at all? @doni49: There would never be more than one client logged on, but you are right it's a risk. Maybe I somehow could inhibit further page access while someone is already logged on... Link to comment https://forums.phpfreaks.com/topic/219476-php-repeating-interval-function/#findComment-1138010 Share on other sites More sharing options...
Alfred Posted November 23, 2010 Author Share Posted November 23, 2010 well... I kind of solved the problem. I created an iframe on an external php page that refreshes every X seconds without refreshing the whole main page... this is not perfect but a, acceptable workaround this goes into main php file: ... <iframe src='action.php' height='30' width='200'></iframe> ... this goes into the external php file: <html> <head><meta http-equiv="refresh" content="30; URL=action.php" /></head> <body> <?php ... ?> Link to comment https://forums.phpfreaks.com/topic/219476-php-repeating-interval-function/#findComment-1138588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.