Reputation: 4512
Ok, so I have this PHP script that runs in a nice little infinite loop (with sleeps, don't worry). I use it as a page I can go to from any computer to monitor my database statistics. Every 2 seconds, it gets stats from the DB and displays them on the screen.
Now, this works just fine on XAMPP on my Windows machine. I'm trying to get it to work on my linux webserver, running apache2 with PHP 5.3.5, but for some reason it won't actually display anything (it doesn't go to a blank page, it just stays at the page I was at before going to the monitor page, but with the "working" wheel spinning). I feel like this is some sort of caching thing, it doesn't want to display the page until it's finished running the script (although I NEED it to). I use flush() and ob_flush() after every 2 seconds, and I made sure that output_buffering = off and zlib.output_compression = off in my php.ini file.
I realize this question seems to have been asked a lot, but I've tried everything I can find on the subject with ultimate failure.
NOTE: like I said, this works FINE on my XAMPP install with apache and PHP 5.3.6. My question isn't so much about how to find alternatives, but more with regards to WHY it works there but not on my linux webserver.
Upvotes: 1
Views: 718
Reputation: 43850
Here is what you can do,
Have your script write the parameters to the javascript, so you can reload your page every 2 seconds with new parameters. example:
<script type='text/javascript'>
setTimeout(function() {
location.href="http://www.example.com/?jobid=<?php echo $nextJobId ?>";
},2000);
</script>
so if you need to do a Db offset on each sql query, you can pass that parameter in the url. Having an infinite loop might seem like a good idea, but maybe you should reevalute your code and see if you really need it, or if you can implement it this way
Upvotes: 1
Reputation: 27077
Having php script run for an "infinite" amount of time is almost never appropriate. You can:
<meta http-equiv="refresh" content="5">
)All of these ways of approaching the problem would save you the type of headaches you're experiencing now.
Upvotes: 2