|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44955 socket array keys not working as expected
Submitted: 2008-05-09 14:58 UTC Modified: 2008-07-15 11:22 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: fidojones at fidojones dot com Assigned: felipe (profile)
Status: Closed Package: Sockets related
PHP Version: 5.2.6 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: fidojones at fidojones dot com
New email:
PHP Version: OS:


 [2008-05-09 14:58 UTC] fidojones at fidojones dot com
This bugfixed

make work socket arrays some strange. 

I think that some HASH_KEY is not contemplate in switch case line 605

switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(sock_array), &key, &key_len, &num_key, 0, NULL)) {

Nanoweb server, when try to access it, eat cpu at 99% time with this socket patch.

Reproduce code:
$ary = array();
$strone = 'Message From Parent.';
$strtwo = 'Message From Child.';
if (socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $ary) === false) {
    echo "socket_create_pair() failed. Reason: ".socket_strerror(socket_last_error());
$pid = pcntl_fork();
if ($pid == -1) {
    echo 'Could not fork Process.';
} elseif ($pid) {
    if (socket_write($ary[1], $strone, strlen($strone)) === false) {
        echo "socket_write() failed. Reason: ".socket_strerror(socket_last_error($ary[1]));
    if (socket_read($ary[1], strlen($strtwo), PHP_BINARY_READ) == $strtwo) {
        echo "Recieved $strtwo\n";
} else {
    if (socket_write($ary[0], $strtwo, strlen($strtwo)) === false) {
        echo "socket_write() failed. Reason: ".socket_strerror(socket_last_error($ary[0]));
    if (socket_read($ary[0], strlen($strone), PHP_BINARY_READ) == $strone) {
        echo "Recieved $strone\n";

Expected result:
php 5.2.5 result:

bash$ php socket.php 
Recieved Message From Child.
Recieved Message From Parent.

Actual result:
php 5.2.6 result:

bash# php socket.php 
Recieved Message From Child.
bash# Recieved Message From Parent.

An here wait and you should hit return to see the bash prompt again


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-09 16:27 UTC]
Assigned to Felipe who broke this.
 [2008-05-09 17:50 UTC]
The problem isn't related with the patch... It just fixed a problem in socket_select(). Your script doesn't use it.
 [2008-05-09 18:12 UTC] fidojones at fidojones dot com
I'm using the socket.c file in ext/socket/ from php 5.2.5 in php 5.2.6 and all is working fine. And the only diff in socket.c is the patch ,so explain me if not related with this patch, why is working perfect? if I only overwrite the socket.c file...

You should test the script and say me if you see the execution diference and I encourage to try that has been working with all php versions from 4 to 5.2.5 and only fails with php 5.2.6.
 [2008-07-14 21:29 UTC]
Felipe, you break -> you fix. Or revert the patch you applied that obviously causes the problem.
 [2008-07-14 21:45 UTC] fidojones at fidojones dot com
Aparently socket_select acts completely diferent as past versions. Nanoweb server has been fixed to work with this versions:

old version in nanoweb before 5.2.6:

$ns=socket_select($lnset, $write=NULL, $except=NULL, 1);
if ($ns) {	
 if ($lnset[0]==$children_sck) {

new version in nanoweb from 5.2.6:

$ns=socket_select($lnset, $write=NULL, $except=NULL, 1);
if ($ns) foreach ($lnset as $lnact) {
  if ($lnact==$children_sck) {

So I think it's not a bug, but acts different as older versions.
 [2008-07-15 06:44 UTC]
Changes in behavior in minor versions are bugs.
 [2008-07-15 11:22 UTC]
Ok, sorry!

Thanks fidojones for the feedbacks.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Oct 03 00:01:24 2023 UTC