Jump to content

PHP Repeating Interval Function


Alfred

Recommended Posts

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
Share on other sites

@ 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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.