php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50737 stream_set_blocking creates high cpu usage
Submitted: 2010-01-13 09:58 UTC Modified: 2010-01-28 08:44 UTC
From: jason at lentink dot net Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.2.12 OS: Linux
Private report: No CVE-ID: None
 [2010-01-13 09:58 UTC] jason at lentink dot net
Description:
------------
When using stream_set_blocking on a stream will create a huge load on 
cpu. When using this function it uses up to 50% of the cpu. When not 
using this function it will only use 0.1% cpu usage.

Reproduce code:
---------------
$this->_socket = fsockopen($str, $port, $errno, $errstr);
stream_set_blocking($this->_socket, 0); // non blocking

Expected result:
----------------
An socket which will be opened fast. in a non-blocking mode.

Actual result:
--------------
An open socket. But the cpu use is enormous.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-13 12:07 UTC] jani@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2010-01-14 12:13 UTC] jason at lentink dot net
I could provide you guys with a small script
bug i can also point you to the place where the problem exists since 
it happens in Zend Framework.

http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Queu
e/Stomp/Client/Connection.php

The function is used at line 79. What i see on my servers is that when 
there are simultaneous request made to the same script the problem 
increases more rapidly.
 [2010-01-14 12:17 UTC] jani@php.net
I asked for small, complete script NOT for a framework.
 [2010-01-14 12:53 UTC] jason at lentink dot net
Whatever you want :)

http://www.grasvezel.nl/media/software/cpuload.txt

Here is a complete undressed file which only has the problem.
 [2010-01-15 08:56 UTC] jani@php.net
Strike 3. As long as you can not provide a short reproducing script (like described in my first comment to this report) the bug is most likely something you did wrong.
 [2010-01-15 10:48 UTC] jason at lentink dot net
Then we go back to the first post and there is a 2 line example of the 
problem.

Reproduce code:
---------------
<?php
$socket = fsockopen("somehost", 631313, $errno, $errstr);
stream_set_blocking($socket, 0); // non blocking

this is enough to trigger the problem.
I hope this is short enough.
 [2010-01-28 08:44 UTC] jani@php.net
Stil a FAIL:

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known 
 [2010-10-15 22:59 UTC] pdescham49 at gmail dot com
Wow. Nice thread, You'll go far in life with an attitude like that. I assume you are not being paid for this support. If you were my employee I would fire you on the spot.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC