By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

fsockopen error need some help thanks

P: n/a

So I am using php version 4.3.9 and lets say i have a file on the server
called tester.php

so i am using fsockopen to point to that file but it gives me a error below.

$fh = @fsockopen("http://www.mysite.com/teter.php", "80", $errno, $errstr,
180);

111 Connection refused

This server is linux Redhat Enterprise with Apache 2.x

Is there anything i need to edit in the php.ini file or apache file.

Thanks...
Nov 20 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
If using fsockopen, try without the "http://", since fsockopen expects
a host. You could also use reafile, file_get_contents, fopen, etc. on
a URL.

Yoko wrote:
So I am using php version 4.3.9 and lets say i have a file on the server
called tester.php

so i am using fsockopen to point to that file but it gives me a error below.

$fh = @fsockopen("http://www.mysite.com/teter.php", "80", $errno, $errstr,
180);

111 Connection refused

This server is linux Redhat Enterprise with Apache 2.x

Is there anything i need to edit in the php.ini file or apache file.

Thanks...
Nov 21 '06 #2

P: n/a
I get this error when i turn on the error warnings in the php.ini file

Warning: fsockopen(): unable to connect to www.fetchads.com:80 in /var/www/vhosts/fetchads.com/httpdocs/fsock/index.php
on line 62
Hello petersprc,
If using fsockopen, try without the "http://", since fsockopen expects
a host. You could also use reafile, file_get_contents, fopen, etc. on
a URL.

Yoko wrote:
>So I am using php version 4.3.9 and lets say i have a file on the
server called tester.php

so i am using fsockopen to point to that file but it gives me a error
below.

$fh = @fsockopen("http://www.mysite.com/teter.php", "80", $errno,
$errstr, 180);

111 Connection refused

This server is linux Redhat Enterprise with Apache 2.x

Is there anything i need to edit in the php.ini file or apache file.

Thanks...

Nov 22 '06 #3

P: n/a
Try this:

$sock = fsockopen('the.site', 80, $errno, $errstr, 15);

Yoko wrote:
I get this error when i turn on the error warnings in the php.ini file

Warning: fsockopen(): unable to connect to www.fetchads.com:80 in /var/www/vhosts/fetchads.com/httpdocs/fsock/index.php
on line 62
Hello petersprc,
If using fsockopen, try without the "http://", since fsockopen expects
a host. You could also use reafile, file_get_contents, fopen, etc. on
a URL.

Yoko wrote:
So I am using php version 4.3.9 and lets say i have a file on the
server called tester.php

so i am using fsockopen to point to that file but it gives me a error
below.

$fh = @fsockopen("http://www.mysite.com/teter.php", "80", $errno,
$errstr, 180);

111 Connection refused

This server is linux Redhat Enterprise with Apache 2.x

Is there anything i need to edit in the php.ini file or apache file.

Thanks...
Nov 24 '06 #4

P: n/a
Very simple my friend

Solution One
<?php
$host = "www.example.com";
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>

Option 2 (PHP 4 and if the server allow) :
$file = file_get_content("http://www.example.com/test.php");

Option 3:
$f = fopen("http://www.example.com/test.php","r");
while ($r = fread($f, 1024)
print $r;

fclose($f);

Is that useful for you?

--
Cesar Rodas
http://www.phpclasses.org/grank (A PHP implementation of PageRank)
On Nov 20, 7:40 pm, Yoko <n...@na.cawrote:
So I am using php version 4.3.9 and lets say i have a file on the server
called tester.php

so i am using fsockopen to point to that file but it gives me a error below.

$fh = @fsockopen("http://www.mysite.com/teter.php", "80", $errno, $errstr,
180);

111 Connection refused

This server is linux Redhat Enterprise with Apache 2.x

Is there anything i need to edit in the php.ini file or apache file.

Thanks...
Nov 25 '06 #5

P: n/a
On 25 Nov 2006 05:53:54 -0800, sa****@gmail.com wrote:
>Solution One
<?php
$host = "www.example.com";
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
This has a common but serious mistake - you're claiming to be an HTTP/1.1
client, but you haven't implemented Chunked transfer encoding. This is a
mandatory requirement for HTTP/1.1 clients, and it's quite common that servers
use it. If you don't handle it, the data will appear to be "corrupted".

The other solutions you posted use PHP's built-in HTTP user agent code, which
does handle this encoding correctly. Alternatively the code above could be
changed to use HTTP/1.0.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Nov 25 '06 #6

P: n/a
Good point... Thanks you...
Here's the new code.

<?php
$host = "www.example.com";
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {

$out = "GET / HTTP/1.0\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}

?>
On Nov 25, 10:15 am, Andy Hassall <a...@andyh.co.ukwrote:
On 25 Nov 2006 05:53:54 -0800, sad...@gmail.com wrote:
Solution One
<?php
$host = "www.example.com";
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?This has a common but serious mistake - you're claiming to be an HTTP/1.1
client, but you haven't implemented Chunked transfer encoding. This is a
mandatory requirement for HTTP/1.1 clients, and it's quite common that servers
use it. If you don't handle it, the data will appear to be "corrupted".

The other solutions you posted use PHP's built-in HTTP user agent code, which
does handle this encoding correctly. Alternatively the code above could be
changed to use HTTP/1.0.

--
Andy Hassall :: a...@andyh.co.uk ::http://www.andyh.co.ukhttp://www.and....co.uk/space:: disk and FTP usage analysis tool
Nov 25 '06 #7

P: n/a
This is another Solution is this, but think that you'll need to analize
the headers for decompress is the content is compressed or am I wrong?:

<?php
$host = "www.example.com";
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Accept-Language: en-us, en;q=0.50\r\n";
$out .= "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n";
$out .= "Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}

?>
On Nov 25, 10:15 am, Andy Hassall <a...@andyh.co.ukwrote:
On 25 Nov 2006 05:53:54 -0800, sad...@gmail.com wrote:
Solution One
<?php
$host = "www.example.com";
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?This has a common but serious mistake - you're claiming to be an HTTP/1.1
client, but you haven't implemented Chunked transfer encoding. This is a
mandatory requirement for HTTP/1.1 clients, and it's quite common that servers
use it. If you don't handle it, the data will appear to be "corrupted".

The other solutions you posted use PHP's built-in HTTP user agent code, which
does handle this encoding correctly. Alternatively the code above could be
changed to use HTTP/1.0.

--
Andy Hassall :: a...@andyh.co.uk ::http://www.andyh.co.ukhttp://www.and....co.uk/space:: disk and FTP usage analysis tool
Nov 25 '06 #8

P: n/a
This is another Solution is this, but think that you'll need to analize
the headers for decompress is the content is compressed or am I wrong?:

<?php
$host = "www.example.com";
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Accept-Language: en-us, en;q=0.50\r\n";
$out .= "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n";
$out .= "Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}

?>
On Nov 25, 10:15 am, Andy Hassall <a...@andyh.co.ukwrote:
On 25 Nov 2006 05:53:54 -0800, sad...@gmail.com wrote:
Solution One
<?php
$host = "www.example.com";
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?This has a common but serious mistake - you're claiming to be an HTTP/1.1
client, but you haven't implemented Chunked transfer encoding. This is a
mandatory requirement for HTTP/1.1 clients, and it's quite common that servers
use it. If you don't handle it, the data will appear to be "corrupted".

The other solutions you posted use PHP's built-in HTTP user agent code, which
does handle this encoding correctly. Alternatively the code above could be
changed to use HTTP/1.0.

--
Andy Hassall :: a...@andyh.co.uk ::http://www.andyh.co.ukhttp://www.and....co.uk/space:: disk and FTP usage analysis tool
Nov 25 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.