|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57439 CPU goes sky high in case of a disconnection
Submitted: 2006-12-18 08:32 UTC Modified: 2012-10-06 09:22 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: galvao at galvao dot eti dot br Assigned:
Status: No Feedback Package: ssh2 (PECL)
PHP Version: Irrelevant OS: Windows XP Professional
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: galvao at galvao dot eti dot br
New email:
PHP Version: OS:


 [2006-12-18 08:32 UTC] galvao at galvao dot eti dot br
I'm making a SSH connection to a machine and everything runs fine. Problem is that, since I'm also opening a shell, if the connection breaks while the ssh commands are being executed the PHP script hangs and starts to consume 99% of CPU resources.

What I'm doing to simulate this is the following:

1) I run the script on a Windows XP Professional machine.
2) At the Linux server I locate the PID of the script connection and kill it.

Reproduce code:

Expected result:
One of the following should happen:

1) Since the stream_set_timeout command was used and the connection was closed the stream should time out and return an error msg.

2) Since a max_execution_time was defined PHP should abort script execution because of it.

also, $STDOUT should return false.

Actual result:
The script hangs, consuming 99% of CPU and never dying, not even after the max_execution_time time limit.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-15 11:57 UTC] jian at theorchard dot com
I'm running PHP 5.2 under Windows environment using shell execution.  Tried the script on both XP Pro and Server 2003 64bit edition.

Similar bug has occurred to me.  PHP warnings were generated when losing connection to remote server.  I have a do...while loop in my script to try to reconnect to the remote server if the connection gets lost for a maximum of five times.  In my case, if the remote ssh connection cannot be re-established, the php script gets killed by the server.
 [2012-06-14 07:46 UTC]
Both expected results should not happen.

1) stream_set_timeout won't kick in because it was never implemented. This is bug 
#56377. I'm working on getting that fixed.

2) max_execution_time will not interrupt fgets(). from the manual:
"The set_time_limit() function and the configuration directive max_execution_time 
only affect the execution time of the script itself. Any time spent on activity 
that happens outside the execution of the script such as system calls using 
system(), stream operations, database queries, etc. is not included when 
determining the maximum time that the script has been running. This is not true 
on Windows where the measured time is real."

I don't know the behaviour on Windows as I don't have a windows box available, 
but see for yourself:

$line = fgets(STDIN);
echo 'You typed: ' .  $line;

Still there is something wrong, fgets($sshShell) should not consume a cpu in 
blocking state.

This bug might well be fixed in the meantime, since it's been a few years. Can 
you please test if this problem still exists with recent libssh2 and ssh2 
extension versions?
 [2012-06-14 07:47 UTC]
-Status: Open +Status: Feedback
 [2012-10-06 09:22 UTC]
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.

 [2012-10-06 09:22 UTC]
-Status: Feedback +Status: No Feedback
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Oct 06 15:05:53 2022 UTC