php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40151 fsockopen can not work?
Submitted: 2007-01-17 09:34 UTC Modified: 2007-01-22 07:01 UTC
From: playercd8 at hotmail dot com Assigned:
Status: Not a bug Package: Network related
PHP Version: 5.2.0 OS: FreeBSD5.5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: playercd8 at hotmail dot com
New email:
PHP Version: OS:

 

 [2007-01-17 09:34 UTC] 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:
----------------
..


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-17 10:01 UTC] tony2001@php.net
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-19 02:23 UTC] 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 (!@$url_parsed['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(!@$port)

		{

			if ($scheme == "https")

				$port = 443;

			else

				$port = 80;

		}

		if(!@$path) $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-19 04:25 UTC] playercd8 at hotmail dot com
I can manual telnet remote WebServer to get a html-file at FreeBSD.

but, I can not use fsockopen at FreeBSD.

Why?
 [2007-01-19 08:07 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 [2007-01-19 09:39 UTC] playercd8 at hotmail dot com
are your answer like "PHP5 can not sure to use fsockopen at FreeBSD"?

is fsockopen not support at FreeBSD, now?

or, you are remove PHP5 able use at FreeBSD?

It's Bug? or not bug?
 [2007-01-22 06:18 UTC] playercd8 at hotmail dot com
Because, is PHP Version too new ?

use 
<?php
phpinfo();
?>

-------------------------------------
OS = FreeBSD 5.5
PHP Version 5.2.0

Configure Command=
'./configure' '--enable-versioning' '--enable-memory-limit' '--with-layout=GNU' '--with-config-file-scan-dir=/usr/local/etc/php' '--disable-all' '--enable-libxml' '--with-libxml-dir=/usr/local' '--enable-reflection' '--enable-spl' '--program-prefix=' '--enable-fastcgi' '--with-apxs2=/usr/local/sbin/apxs' '--with-regex=php' '--with-zend-vm=CALL' '--prefix=/usr/local'

PHP API 	= 20041225
PHP Extension 	= 20060613
Zend Extension 	= 220060519 

but, Sockets Support =	enabled ? why?

---------------------------------------------------
OS = Fedora Core 6
PHP Version 5.1.6

Configure Command =
'./configure' '--build=i386-redhat-linux' '--host=i386-redhat-linux' '--target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-curl' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-expat-dir=/usr' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--with-kerberos' '--enable-ucd-snmp-hack' '--with-unixODBC=shared,/usr' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' '--with-mime-magic=/etc/httpd/conf/magic' '--without-sqlite' '--with-libxml-dir=/usr' '--with-xml' '--with-apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd' '--without-odbc' '--disable-dom' '--disable-dba' '--without-unixODBC' '--disable-pdo' '--disable-xmlreader' '--disable-xmlwriter'

PHP API 	= 20041225
PHP Extension 	= 20050922
Zend Extension 	= 220051025

Sockets Support = enabled
 [2007-01-22 07:01 UTC] tony2001@php.net
Most likely because of some kind of firewall.
Not PHP problem.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC