php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42467 fsockopen: "Operation now in progress"
Submitted: 2007-08-29 09:30 UTC Modified: 2007-08-30 06:57 UTC
Votes:8
Avg. Score:4.2 ± 1.0
Reproduced:7 of 7 (100.0%)
Same Version:4 (57.1%)
Same OS:4 (57.1%)
From: daniel dot buschke at nextiraone dot de Assigned:
Status: Wont fix Package: Streams related
PHP Version: 5CVS-2007-08-29 (snap) OS: Linux
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daniel dot buschke at nextiraone dot de
New email:
PHP Version: OS:

 

 [2007-08-29 09:30 UTC] daniel dot buschke at nextiraone dot de
Description:
------------
When trying to connect to a host via fsockopen and socksify (see dante) I get following:

PHP Warning:  fsockopen(): unable to connect to 1.2.3.4:99 (Operation now in progress) in /socksify.php on line 15

But "Operation now in progress" is not an error which tolds that connect fails.

socket_create and socket_connect are working fine.

seems like #39803 but has different version. Patch of #38568 did not work

Reproduce code:
---------------
<?php
        $sock = fsockopen('1.2.3.4', 99);
?>

Expected result:
----------------
$sock should be an handle which is usable with fread or sth like this

$sock !== FALSE

Actual result:
--------------
PHP Warning:  fsockopen(): unable to connect to 1.2.3.4:99 (Operation now in progress) in /socksify.php on line 15

$sock === FALSE

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-29 09:51 UTC] jani@php.net
I can not reproduce with that one liner. It simply hangs.
Obviously you have some bigger script to test with?
 [2007-08-29 11:05 UTC] daniel dot buschke at nextiraone dot de
<?php
        $sock = fsockopen('69.147.83.196', 80);
?>

This one trys to connect to an IP of bugs.php.net. Remember that I run this script with socksifiy in front:

socksify php -f socksify.php


I'm sure it is not easy for you to reproduce this bug. So here is the whole story:

I want to connect from Server A (lan) to a Server B (internet). Server A is behind a firewall which drops allmost everything. So if I want to connect to the internet I have to use SOCKS5. Therefore I have to use socksify.

socks_create and socks_connect are working fine! So this is not a problem of socksify. But I can not use socks because I want to use ssh2_* buildins which are using the same core functions as fsockopen and which result in same problem.
 [2007-08-29 11:28 UTC] jani@php.net
Try this (timeout included) instead:

<?php
        $sock = fsockopen('1.2.3.4', 99, $errno, $errstr, 30);
?>


 [2007-08-29 11:43 UTC] daniel dot buschke at nextiraone dot de
webserver_dev sandbox # cat fsockopen_timeout.php
<?php
        fsockopen('69.147.83.196', 80, $errno, $errstr, 30);

        echo "errno: $errno\n";
        echo "errstr: $errstr\n";
?>
webserver_dev sandbox # socksify php -f fsockopen_timeout.php
PHP Warning:  fsockopen(): unable to connect to 69.147.83.196:80 (Operation now in progress) in /www/vhosts/dev/sandbox/fsockopen_timeout.php on line 2
errno: 115
errstr: Operation now in progress


of curse it is equal to '1.2.3.4', 99
 [2007-08-29 11:45 UTC] daniel dot buschke at nextiraone dot de
here is the test script that shows that socket_create and socket_connect is working:

webserver_dev sandbox # cat socks.php
<?php
        define('TCP', 6);

        $sock = socket_create(AF_INET, SOCK_STREAM, TCP);
        socket_connect($sock, '69.147.83.196', 80);

        socket_send($sock, "GET /\n", strlen('GET / HTTP 1.0'), 0);
        echo socket_read($sock, 100);

        socket_close($sock);
?>
webserver_dev sandbox # socksify php -f socks.php
This document is located <a href="/viewvc.cgi/">here</a>.
 [2007-08-29 11:48 UTC] jani@php.net
EINPROGRESS is quite normal error when you have non-blocking socket. I guess this sockify thing messes this.
 [2007-08-29 11:50 UTC] jani@php.net
And as fsockopen() is meant for quick'n'dirty socket stuff and does work in normal situation -> wont fix. You have a very special case and thus you need to use the lower level functions.
 [2007-08-29 12:11 UTC] daniel dot buschke at nextiraone dot de
Ok, there are some things:

1. fsockopen is using a blocking socket, isn't it?
2. I told, that fsockopen is using the same functions as ssh2_*()

If you want to use ssh2 functionallity you have the same problem:

--------------------------------------------
webserver_dev sandbox # cat ssh.php
<?php

$ssh_con = ssh2_connect('84.38.64.78');
$fingerprint = ssh2_fingerprint($ssh_con, SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX);

echo $fingerprint

?>
webserver_dev sandbox # socksify php -f ssh.php
PHP Warning:  ssh2_connect(): Unable to connect to 84.38.64.78 on port 22 in /www/vhosts/dev/sandbox/ssh.php on line 3
PHP Warning:  ssh2_connect(): Unable to connect to 84.38.64.78 in /www/vhosts/dev/sandbox/ssh.php on line 3
PHP Warning:  ssh2_fingerprint() expects parameter 1 to be resource, boolean given in /www/vhosts/dev/sandbox/ssh.php on line 4
--------------------------------------------


Please try this script with you own ssh server. My will drop you if you try!



So, this is a bug of ssh2 from pecl, because they are using that "quick'n'dirty socket stuff"?!
 [2007-08-30 06:57 UTC] daniel dot buschke at nextiraone dot de
DOH! Just setting this bug from Feedback to Wont Fix without answers is not fine!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC