php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23131 If fsockopen can't open connection, if(!fp) doesn't run
Submitted: 2003-04-09 09:01 UTC Modified: 2003-04-21 09:22 UTC
Votes:5
Avg. Score:4.4 ± 0.8
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:3 (75.0%)
From: kangstarr at hotmail dot com Assigned:
Status: No Feedback Package: Sockets related
PHP Version: 4.3.1 OS: Windows XP
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2003-04-09 09:01 UTC] kangstarr at hotmail dot com
$fp = fsockopen("kang.kicks-ass.net", "8000", &$errno, &$errstr, 20); //open connection
if(!$fp) {
   echo "No Connection";
   $success=2;  //set if no connection
}

Basically I'm checking to see if my SHOUTcast server is running.  If the shoutcast server is not running, and it tries to open the connection I get these html warnings.

Warning: fsockopen() [function.fsockopen]: php_hostconnect: connect failed in e:\inetpub\wwwroot\scast\scastxml.php on line 37

Warning: fsockopen() [function.fsockopen]: unable to connect to kang.kicks-ass.net:8000 in e:\inetpub\wwwroot\scast\scastxml.php on line 37

Fatal error: Maximum execution time of 30 seconds exceeded in e:\inetpub\wwwroot\scast\scastxml.php on line 37

I'm running WinXP, Apache 1.3, PHP 4.3.1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-09 09:24 UTC] kangstarr at hotmail dot com
Ok, I forgot to note that I'm calling the php from another php.

index.php includes scastxml.php

scastxml.php is where the script is located.

When I go directly to scastxml.php the script works fine.  When I goto index.php which includes the scastxml.php, the script only works if I set the fsockopen timeout to 5 or less.  Can someone explain to me why this happens??
 [2003-04-09 10:06 UTC] wez@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Probably already fixed; please try a snapshot
 [2003-04-21 09:22 UTC] sniper@php.net
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.


 [2005-04-05 14:47 UTC] birkholz at web dot de
On my windows-system with apache 2.0.53 and php 4.3.11 a call to fsockopen with the timeout-parameter seems to change the maximum-execution-time out the complete script to the timeout-value passed to fsockopen.
I the connection-try failes because of a timeout, php raises a fatal error "Fatal error: Maximum execution time of 10 seconds exceeded in test.php on line xxx" and terminates the script-execution.

It should not terminate the script but return FASLE after 10 seconds and than should fill the passed $errstr-var with "Connection timeout" or something like that and the $errno-var with the corresponding error-number.

On this code:

<?php
// This hostname should not answer on the socket-request
// On windows-Systems any call to a non-open port will
// produce a timeout
if ($fp = fsockopen('localhost',12345,$errno, $errstr, 10))
{
  print "connection established";
}

else
{
  print "Error: \"$errstr\" [$errno] occured.";
}

print "\nAfter the fsockopen()"
?>

it should return:
SNIP-->
Error: "Connection timeout" [123] occured.
After the fsockopen()
<--SNIP

but returns
SNIP-->
Warning: fsockopen(): unable to connect to localhost:12345 in D:\htdocs\test.php on line 5

Fatal error: Maximum execution time of 10 seconds exceeded in D:\htdocs\test.php on line 5
<--SNIP

The general error-handling of the fsockopen()-function should fixed to fill the passed $errno and $errstr variables instead of raising warnings.

Greets,
Dennis
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Nov 28 03:03:14 2021 UTC