Bug #67845 [NEW]: Resource ids may overflow when running a daemon or large app

From: Date: Thu, 14 Aug 2014 21:02:49 +0000
Subject: Bug #67845 [NEW]: Resource ids may overflow when running a daemon or large app
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187132@lists.php.net to get a copy of this message
From:             blondie101010 at hotmail dot com
Operating system: Gentoo
PHP version:      Irrelevant
Package:          Streams related
Bug Type:         Bug
Bug description:Resource ids may overflow when running a daemon or large app

Description:
------------
Working on a socket server, I had wondered what would happen when the
resource id would reach 31 bits long, so I used the code below to test
it.

Inevitably it failed at 2147483647.

A proactive solution would be for it to wrap once it reaches its limit,
of course checking to see if the resource is already assigned.

An alternative would be to reuse freed resource ids but I can already
see many bad programmers who would be scared by that option.

Test script:
---------------
<?php

for ($i = 0; $i < 5000000000; $i ++)
{
        $fp = fopen("/dev/null", "w");
        if (($i % 500000) == 0)
        {
                var_dump($fp);
                system("date");
        } // if
        fclose($fp);
} // for

?>

Expected result:
----------------
Keep running as there are actually no resources in use.

Actual result:
--------------
It starts giving errors when it exceeds 31 bits on my 32 bit system.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=67845&edit=1
-- 



Thread (4 messages)

« previous php.bugs (#187132) next »