|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35062 [PATCH] socket_read() produces warnings on non blocking sockets
Submitted: 2005-11-02 08:52 UTC Modified: 2005-12-04 18:32 UTC
From: dima at dimych dot sumy dot ua Assigned:
Status: Closed Package: Sockets related
PHP Version: 5CVS, 4CVS (2005-11-10) (cvs) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: dima at dimych dot sumy dot ua
New email:
PHP Version: OS:


 [2005-11-02 08:52 UTC] dima at dimych dot sumy dot ua
Use of socket_read() on non blocking sockets produces warinigs like:
socket_read() unable to read from socket [35]: Resource temporarily unavailable

I`m storing all php errors in log file /var/log/php.log.
This warning causes overflow of /var partition because socket_read() called to wait icmp message. 

Reproduce code:
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_connect($socket, $host, null);
$startTime = microtime_float(true);
socket_send($socket, $data, strLen($data), 0);
while((microtime_float() - $startTime) < 0.5) {
  $mt = microtime_float();
  if (socket_read($socket, 255)) {

Expected result:
no warnings in php.log

Actual result:
I`m receive huge count of warinigs in my php.log file like this:
socket_read() unable to read from socket [35]: Resource temporarily unavailable


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-02 14:37 UTC] dima at dimych dot sumy dot ua
I`m not agree what it is bogus....

part of code from ext/sockets/sockets.c:
-- code --
if (type == PHP_NORMAL_READ) {
                retval = php_read(php_sock->bsd_socket, tmpbuf, length, 0);
        } else {
                retval = recv(php_sock->bsd_socket, tmpbuf, length, 0);

        if (retval == -1) {
                PHP_SOCKET_ERROR(php_sock, "unable to read from socket", errno);
-- end of code --
As you can see any processing for EAGAIN not exists. Warning will be generated in any case. 

1. I`m developing icmp ping function and "no reply" is not an error in my program.
2. Function, what can say is any data to receive, not exists.
3. I do not want to turn warnings off. Because I need them in other places.
 [2005-11-04 14:53 UTC] dima at dimych dot sumy dot ua
I`m look everyware in the Internet and don`t find any workaround for this problem. And error logs still growing...

This code decreases count of warnings:
-- code --
$startTime = microtime_float(true);
socket_send($socket, $package, strLen($package), 0);
$to = array('sec' => 0, 'usec' => 500000);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $to);
if (socket_read($socket, 4096)) {
  return microtime_float() - $startTime;
-- end of code --
my "ping" function launches once per 5 minutes for around 50 hosts, but not all of them alive. Dead hosts causes warnings.
 [2005-11-04 16:23 UTC]
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #21197
 [2005-11-05 22:13 UTC]
opening it again, as this seems a different issue.
We should have the EAGAIN constant and use it for non-blocking sockets. returning false isnt't a good idea.
 [2005-11-10 00:17 UTC]
After the reading the bug report carefully, the only problem here is that socket_read() shouldn't produce a warning when errno==EAGAIN. The return value of the function doesn't need/can't be changed.

The constant SOCKET_EAGAIN is already defined, so there's also a doc bug :) (all SOCKET_* need to be documented)

The patch:
 [2005-11-10 08:45 UTC]
Nuno, I think you will only get some feedback on your patch if  you either commit it, or post it to internals list.
 [2005-11-10 11:34 UTC]
Ok, I've sent an e-mail to internals ML.
But I cannot commit the patch, because I don't have enough karma.
 [2005-12-04 18:32 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 11:01:31 2024 UTC