php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32075 sockets do not detect disconnect
Submitted: 2005-02-23 08:35 UTC Modified: 2005-02-23 19:20 UTC
From: mike_harris02135 at yahoo dot com Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 4.3.10 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mike_harris02135 at yahoo dot com
New email:
PHP Version: OS:

 

 [2005-02-23 08:35 UTC] mike_harris02135 at yahoo dot com
Description:
------------
Ive been on the forums and noone seems to be able to help with this.

Im writing a jabber client with php.  I connect to the server, send a message, sleep for 20 seconds (kill the server during this time), then send another message, and the code used to send the message does not report any error.

Reproduce code:
---------------
function WriteToSocket($data)
	{
		echo "\nIn WriteToSocket: $data\n";
		echo "-------------Socket = " . $this->socket . "\n";

		if(socket_last_error($this->socket))
		{
			print "Detected error\n";
			echo socket_strerror(socket_clear_error($this->socket));
		}

		
		return socket_write($this->socket, $data, strlen($data));
		
	}

Expected result:
----------------
i expect socket_last_error to report that the socket was closed unexpectedly.  Incidently, when I create the socket i always get an error with unknown error code, but the server receives the message just fine.  Or the socket_write method would return 0, or the socket reference would be null.

Actual result:
--------------
The code does not indicate any error, and reports that n bytes were written.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-23 08:40 UTC] mike_harris02135 at yahoo dot com
incidently, I also tried using the fsockopen method and fread and fwrite, and that did not detect an error either...
 [2005-02-23 09:06 UTC] sniper@php.net
First you need to fix the obvious errors in your script.
Like echo socket_strerror(socket_clear_error($this->socket));
And such. (socket_clear_error() does not return anything)
Then if you still can't get it to work, ask further support questions on how to use PHP and how to use sockets on the mailing lists. No bug here.


 [2005-02-23 19:20 UTC] mike_harris02135 at yahoo dot com
sniper

what are the other errors -- note this is not the entire class, just the part that sends.  Even if I fix the socket_clear_error, it detects an error that it cannot id, that it also detected when the send worked.

-------------Socket = Resource id #7
Detected error
Unknown error 1970037110
SendPacket: test = 271

Note its still reporting that 271 bytes were written....
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 05:01:29 2024 UTC