|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-11-02 08:52 UTC] dima at dimych dot sumy dot ua
Description:
------------
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);
socket_set_nonblock($socket);
while((microtime_float() - $startTime) < 0.5) {
$mt = microtime_float();
if (socket_read($socket, 255)) {
break;
}
}
socket_close($socket);
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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 03:00:01 2025 UTC |
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); efree(tmpbuf); RETURN_FALSE; } -- 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.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); socket_set_block($socket); $to = array('sec' => 0, 'usec' => 500000); socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $to); if (socket_read($socket, 4096)) { socket_close($socket); return microtime_float() - $startTime; } socket_close($socket); -- 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.