E
exxos
Guest
It seems sleep() pauses not only the script from running but also the output ? like if I use..
sleep(1);
echo "test";
sleep(1);
echo "test";
sleep(1);
echo "test";
it would actually wait 3 seconds then display the 3 test lines all at once.
What I am trying to do is loop a php function to read the database every few seconds.. I cant just leave it in a constant loop as it would burn cpu time to the max and max out the server.
What I was doing was just reloading the page with JS every 20 seconds, the page is only a few lines of HTML, but with a few users connected its maxing out 100MB or more in just simple transfers.
So rather than keep refreshing the page, I thought I would write a php script which just includes the html page, and the php would just reload itself , which would update the html content. Being that the php loop would just check the database (sql) every few seconds to see if it needs to refresh the data or not.. however due to said reasons, the sleep() function can't be used in this way.
So I am now stuck with how to go about doing this now ?
at the moment its just
main program loop, which loads a php script into a div, the php script includes the html file...
the old way was, main program loop, which loads a html file into the div , then a java loop (in the main program) reloads the html file.. I've squashed the html data was much as possible, but even a few lines being updated every few seconds by many users is a lot of data transfer!
The html data changes when a user posts, but it also writes a random value to the sql database, which I was trying to read from the php script to see if the number had changed or not. which would solve the problem.. but I can't loop the php script every second to check the number :-(
sleep(1);
echo "test";
sleep(1);
echo "test";
sleep(1);
echo "test";
it would actually wait 3 seconds then display the 3 test lines all at once.
What I am trying to do is loop a php function to read the database every few seconds.. I cant just leave it in a constant loop as it would burn cpu time to the max and max out the server.
What I was doing was just reloading the page with JS every 20 seconds, the page is only a few lines of HTML, but with a few users connected its maxing out 100MB or more in just simple transfers.
So rather than keep refreshing the page, I thought I would write a php script which just includes the html page, and the php would just reload itself , which would update the html content. Being that the php loop would just check the database (sql) every few seconds to see if it needs to refresh the data or not.. however due to said reasons, the sleep() function can't be used in this way.
So I am now stuck with how to go about doing this now ?
at the moment its just
main program loop, which loads a php script into a div, the php script includes the html file...
the old way was, main program loop, which loads a html file into the div , then a java loop (in the main program) reloads the html file.. I've squashed the html data was much as possible, but even a few lines being updated every few seconds by many users is a lot of data transfer!
The html data changes when a user posts, but it also writes a random value to the sql database, which I was trying to read from the php script to see if the number had changed or not. which would solve the problem.. but I can't loop the php script every second to check the number :-(