![]() That being said, though, I'll have to agree that there are very few valid use cases for sleep, and most situations could no doubt be better handled using a different approach. I guess there's at least the off chance that what I'm doing is not entirely evil ? The Link Checker module I released some time ago (it was never quite finished, hopefully I'll get a chance to work more on it soon.ish) makes use of a crawler script that is intended to run as a background process and (u)sleeps between external requests. Reading this made me wonder if I should rethink my strategy, but a quick Google search for "is php sleep always bad" resulted in this Stack Overflow thread discussing valid use cases for sleep – and sure enough, the first one raised was "some kind of a crawler". Update This format here is for /etc/crontab. You can also use instead of &, but in this case it doesnt matter because sleep returns 0 always. Old thread and this is a bit off-topic, but this bit caught my attention, so I thought I'd mention it. 6,496 6 39 78 Add a comment 2 Answers Sorted by: 4 That is absolutely correct. Nowadays, websockets are also used to split off parts of the work to different processes and notify the "owning" session of changes of state in the backend. There also fine differences in buffering behaviour depending on how PHP is executed (mod_php, FastCGI, classic CGI.) The usual solution to situations where you are tempted to call sleep() is to poll until the condition you need to wait for has been reached, either using classic reloads for the current page or with AJAX. sleep() blocks the whole thread it is called in, and under heavier load, it makes servers utterly unresponsive. It's very, very bad practice to use sleep() in a server side script, that is why documentation on working around the pecularities of PHP's buffering (and thread execution) is so sparse. Note: This directive is hardcoded to Off for the CLI SAPI Integer = Enables the buffer and sets its maximum size in bytes. Note: Output buffering can also be controlled via Output Buffering Control On production servers, 4096 bytes is a good setting for performance emitting less packets due to buffered output versus PHP streaming the output You also may see performance benefits if your server is You may be able to send headers and cookies after you've already sent output interesting side-effects depending on your application and web server. Turning on this setting and managing its maximum buffer size can yield some ![]() will send that data in chunks of roughly the size you specify. If your application's output exceeds this setting, PHP (excluding headers and cookies) PHP should keep internally before pushing that Output buffering is a mechanism for controlling how much output data ![]() Oh and just for the record, this is what my hoster writes about output buffering: Things are not always as they are (simple) explained on php.net and w3schools and a lot of fuzz is behind of it.īut luckily 99% is working as they explain. I have this setting on my hoster: output_buffering = 4096Īnyways thanks everybody for stepping in on this. Same thing, all text is outputted or shown at once at the end. Hi flydev yes I tried your second code also.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |