|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-12-12 01:10 UTC] marcelo at tpn dot com dot br
Description:
------------
The function fsockopen() is always failing and returning -1.
I already tried with differents hostnames and IP address.
I'm using FreeBSD 5.3.
Reproduce code:
---------------
<?php
$fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)\n";
}
?>
Expected result:
----------------
$fp should be TRUE...
Actual result:
--------------
But...
$fp is returning FALSE
$errno is returning 36
$errstr is returning "Operation now in progress"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 19:00:01 2025 UTC |
Yes, I've disabled my firewall. I'm sure that isn't a firewall problem. The problem doesn't depend the hostname or IP address. I got the same error trying to connect to localhost, 127.0.0.1, 10.0.0.9 (internal network) This also didn't work: <?php $fp = fsockopen("127.0.0.1", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)\n"; } ?> This also didn't work (connect to an internal server): <?php $fp = fsockopen("10.0.0.9", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)\n"; } ?> But I can use socket_connect without problems. Example: <? $sockHttp = socket_create(AF_INET, SOCK_STREAM, 0); if (!$sockHttp) { die('socket_create() failed!'); } $resSockHttp = socket_connect($sockHttp, "10.0.0.9", 80); if (!$resSockHttp) { die('socket_connect() failed!'); } ?> I also can use "fetch" utility to get data from these servers. I also wrote a PERL script, and it worked. I also type in prompt "telnet 127.0.0.1 80", "telnet www.google.com 80", the connection was sucessfull. Only while I'm using fsockopen I got errors, always error returns 36 and error string returns "Operation now in progress".I'm using PHP 4.4.4, not PHP 5. network.c has two pieces that uses EINPROGRESS: if ((n = connect(sockfd, addr, addrlen)) < 0) { if (errno != EINPROGRESS) { return -1; } } if (ret == -1 && error == EINPROGRESS) { error = 0; goto retry_again; } Where should I put "if (error == EINPROGRESS) error = 0;" ?An user could fix this problem in PHP 5 adding 3 lines of code in main/network.c. if (!asynchronous) { /* back to blocking mode */ RESTORE_SOCKET_BLOCKING_MODE(sockfd, orig_flags); } /* Start changes */ if (error == EINPROGRESS) { error = 0; } /* End changes */ if (error_code) { *error_code = error; } if (error && error_string) { *error_string = php_socket_strerror(error, NULL, 0); ret = -1; } return ret; I try to modify PHP 4 but the code is a bit different. Can you help me to fix this problem? The system is always returning EINPROGRESS.