php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1451 Problems with blocking socket operations
Submitted: 1999-05-25 14:28 UTC Modified: 1999-06-07 16:28 UTC
From: chr at tv2i dot dk Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.8 OS: Red Hat Linux 6.0
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chr at tv2i dot dk
New email:
PHP Version: OS:

 

 [1999-05-25 14:28 UTC] chr at tv2i dot dk
The following code works on PHP3 versions prior to 3.0.7:

	$fp = fsockopen('localhost', 25);
	echo fgets($fp, 256);

However, on 3.0.8 it appears not to work. Instead the HTTP connection hangs (Apache server status shows mode W even after HTTP connection is closed by the webbrowser).

To make it work on 3.0.8, the following "workaround" can be applied:

	$fp = fsockopen('localhost', 25);
	set_socket_blocking($fp, 0);
	sleep(1);
	echo fgets($fp, 256);

The following also works on 3.0.8 (i.e. the connection is closed by the other part):

	$fp = fsockopen('localhost', 25);
	fputs($fp, "quit\n");
	echo fgets($fp, 256);


Loaded modules: mod_php3, mod_setenvif, mod_unique_id, mod_usertrack, mod_headers, mod_cern_meta, mod_auth_anon, mod_auth, mod_access, mod_alias, mod_userdir, mod_actions, mod_imap, mod_asis, mod_cgi, mod_dir, mod_autoindex, mod_include, mod_status, mod_negotiation, mod_mime, mod_mime_magic, mod_log_referer, mod_log_agent, mod_log_config, mod_env, http_core

[PHP_3]
engine                  =       On
short_open_tag  =       On
asp_tags                =       On
precision               =       14
y2k_compliance  =       Off
safe_mode               =       Off
safe_mode_exec_dir      =

max_execution_time = 30
memory_limit = 8388608

error_reporting =       7
display_errors  =       On
log_errors              =       Off
track_errors    =       Off
warn_plus_overloading   =       Off
magic_quotes_gpc        =       On
magic_quotes_runtime=   Off
magic_quotes_sybase     =       Off
track_vars                      =       On
auto_prepend_file       =
auto_append_file        =
include_path    =
doc_root                =
user_dir                =
upload_max_filesize = 5000000
extension_dir   =       ./

[Syslog]
define_syslog_variables = Off

[mail function]
SMTP                    =       localhost
sendmail_from   =       me@localhost.com
sendmail_path   =

[Debugger]
debugger.host   =       localhost
debugger.port   =       7869
debugger.enabled        =       False

[SQL]
sql.safe_mode   =       Off

[bcmath]
bcmath.scale    =       0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-05-28 07:45 UTC] sas at cvs dot php dot net
fixed in CVS.
 [1999-06-07 16:21 UTC] chr at tv2i dot dk
This bug seems to exist in 3.0.9 also.
 [1999-06-07 16:28 UTC] sas at cvs dot php dot net
You want blocking behaviour:

$fp = fsockopen("localhost", 25);
set_socket_blocking($fp, true);

echo fgets($fp, 512);

fputs($fp, "quit\r\n");

echo fgets($fp, 512);

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 13:00:02 2026 UTC