note 119675 added to function.socket-select
| From: | malcolm.murphy | Date: | Sun, 31 Jul 2016 18:55:12 +0000 |
| Subject: | note 119675 added to function.socket-select | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206141@lists.php.net to get a copy of this message | ||
This was mentioned by [Viorel] above but I think it warrants being repeated...
The example provided by [vardhan ( at ) rogers ( dot ) com], while otherwise exceptional, uses the
value int(0) for $tv_sec which will cause the iteration to loop as fast as possible, consequently
using up any available CPU time.
*** Ideally, $tv_sec should always be set to NULL ***, especially if you are using socket_select in
a loop. If you must temporarily stop listening for events to perform another task, then the timeout
should be as high as possible to reduce CPU strain (another note suggested preventing 100% CPU usage
by setting a low $tv_usec value, which only makes the problem slightly less worse but does not solve
it).
Setting the timeout to an explicit null value is basically the same as setting it to infinite. The
script will only execute the while loop once every time there is an event.
----
Server IP: 72.52.91.14
Probable Submitter: 72.21.69.240
----
Manual Page -- http://php.net/manual/en/function.socket-select.php
Edit -- https://master.php.net/note/edit/119675
Del: integrated -- https://master.php.net/note/delete/119675/integrated
Del: useless -- https://master.php.net/note/delete/119675/useless
Del: bad code -- https://master.php.net/note/delete/119675/bad+code
Del: spam -- https://master.php.net/note/delete/119675/spam
Del: non-english -- https://master.php.net/note/delete/119675/non-english
Del: in docs -- https://master.php.net/note/delete/119675/in+docs
Del: other reasons-- https://master.php.net/note/delete/119675
Reject -- https://master.php.net/note/reject/119675
Search -- https://master.php.net/manage/user-notes.php