ID:               40151
 User updated by:  playercd8 at hotmail dot com
 Reported By:      playercd8 at hotmail dot com
 Status:           Open
 Bug Type:         Network related
 Operating System: FreeBSD5.5
 PHP Version:      5.2.0
 New Comment:

I can manual telnet remote WebServer to get a html-file at FreeBSD.

but, I can not use fsockopen at FreeBSD.

Why?


Previous Comments:
------------------------------------------------------------------------

[2007-01-19 02:23:15] playercd8 at hotmail dot com

function HttpRequest, It can run at PHP of Fedora Core 6.
but, Why it can not run at FreeBSD ?

Source code of the function, from 
http://www.webdeveloper.com/forum/archive/index.php/t-117095.html
, and my some fix it.



PHP work at FreeBSD, It can use socket_connect/socket_recv/socket_write
...etc.
but, why It can not use fsockopen ?

Why ?
---------------------------------------------

        function HttpRequest( $url, $method = "GET", $data = NULL,
$additional_headers = NULL, $followRedirects = true )

        {

        # in compliance with the RFC 2616 post data will not redirected

            $method = strtoupper($method);

        $url_parsed = @parse_url($url);

            if ([EMAIL PROTECTED]'scheme']) $url_parsed =
@parse_url('http://'.$url);

        extract($url_parsed);

                

                $data_get = NULL;

            if(is_array($data))

        {

        $ampersand = '';

                $temp = NULL;

                        foreach($data as $k => $v)

                {

                                if ($k != "0")

                                {

                                $temp .= 
$ampersand.urlencode($k).'='.urlencode($v);

                                        $ampersand = '&';

                                }

                        }

                        $data_get = $temp;

                }

                if([EMAIL PROTECTED])

                {

                        if ($scheme == "https")

                                $port = 443;

                        else

                                $port = 80;

                }

                if([EMAIL PROTECTED]) $path = '/';

                if(($method == "GET") and (@$data_get)) $path .= "?".$data_get;

                
                #debug  
                if ($this->debug == true)       echo $path;     
        

                $out = "$method $path {$_SERVER['SERVER_PROTOCOL']}\r\n";

                $out .= "Host: $host\r\n";


                if($method == 'POST')

                {

                        $out .= "Content-type: 
application/x-www-form-urlencoded\r\n";

                        $out .= "Content-length: " . @strlen($data_get) . 
"\r\n";

                }

                $out .= (@$additional_headers)?$additional_headers:'';

                $out .= "Connection: Close\r\n\r\n";

                if($method == "POST") $out .= $data_get."\r\n";

                #debug
                if ($this->debug == true)       echo $out;
                
                #fix https

                $openhost = ($scheme == "https" ? "ssl://" : "").$host;

                #debug

                if ($this->debug == true)       echo
"OpenSocket:".$openhost."(".$port.")";


                if(!$fp = @fsockopen($openhost, $port, $errno, $errstr, 15))

                {
                        #debug

                        if ($this->debug == true)       echo "Now can not open
socket.\nError($errno) $errstr\n";


                        return false;

                }

                fwrite($fp, $out);

                

                while (!feof($fp))

                {

                        $s = fgets($fp, 128);


                        #debug

                        if ($this->debug == true)       echo "\n".$s;

                        

                        if ( $s == "\r\n" )

                        {

                                $foundBody = true;

                                continue;

                        }

                        if ( $foundBody )

                        {

                                $body .= $s;

                        } else {

            

                                #echo $s;

            

                                if( ($followRedirects) and 
(preg_match('/^Location:(.*)/i', $s,
$matches) != false) )

                                {

                                        fclose($fp);

                                        if (strpos(trim($matches[1]), 'http') 
=== false)

                                        {

                                                $urlTo = trim($matches[1]);

                                                $urlLocation = ($scheme == 
'https' ? 'https://' :
'http://').($host).(substr($urlTo, 0, 1) == '/' ? '' : '/').($urlTo);

                                                return $this->HttpRequest( 
$urlLocation );

                                        }

                                        else

                                                return $this->HttpRequest( 
trim($matches[1]) );

                                }

                                $header .= $s;

                                
if(preg_match('@HTTP[/]1[.][01x][\s]{1,}([1-5][01][0-9])[\s].*$@',
$s, $matches))

                                {

                                        $status = trim($matches[1]);

                                }

                        }

                }

                fclose($fp);

                return array('head' => trim($header), 'body' => trim($body), 
'status'
=> $status);

        }

------------------------------------------------------------------------

[2007-01-17 10:01:48] [EMAIL PROTECTED]

Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.




------------------------------------------------------------------------

[2007-01-17 09:34:56] playercd8 at hotmail dot com

Description:
------------
$errno is return 671845376
$errstr is not retuen any string
Why I can not use fsockopen to work ?

Reproduce code:
---------------
                if(!$fp = @fsockopen($openhost, $port, $errno, $errstr, 15))

                {
                        #debug

                        if ($this->debug == true)       echo "Now can not open
socket.\nError($errno) $errstr\n";


                        return false;

                }

Expected result:
----------------
..



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=40151&edit=1

Reply via email to