php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34654 Ticks aren't run when PHP is blocking
Submitted: 2005-09-27 10:52 UTC Modified: 2005-09-28 13:39 UTC
From: sebastian dot forsman at gmail dot com Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 5.0.5 OS: Linux 2.4.28
Private report: No CVE-ID: None
 [2005-09-27 10:52 UTC] sebastian dot forsman at gmail dot com
Description:
------------
I am not sure if this is a bug or a 'feature', but when PHP is blocking, registered tick functions aren't run. It also delays handling of the Unix signals (which use ticks).

Reproduce code:
---------------
http://pastebin.com/375512

Expected result:
----------------
(You need Linux, posix-, pcntl- and socket-functions to run the script.) The code snippet will start a simple single-client server. Try sending a "kill <pid>" from the shell to the process. It won't react to the signal in any way, until a connection is received (try "telnet localhost 22500").

Same applies to registered tick functions. If you modify the code and register a tick function, it is not run at all when socket_accept() is waiting for a connection.

Yes of course you can set the socket non-blocking, but then you are missing the point.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-27 14:18 UTC] marcot@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Nothing strange about this--it's not called blocking for lack of a better name. When a socket enters blocking mode, the application yields control to the socket library, from where it does not return until a socket event takes place. If you want more control, you need to set your sockets to non-blocking mode.
 [2005-09-28 13:39 UTC] sebastian dot forsman at gmail dot com
As I mentioned in my post, yes, you can always set the socket non-blocking. But it's only a workaround, not a fix to the problem. And besides the loop will then consume all of the CPU. Right, you can use sleep(), but hey, come on.

If PHP is supposed to support signals properly etc, as any process should, this behavior has to be changed. It is no excuse that the control is yield to the socket library.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 17:01:28 2024 UTC