Jump to content


This topic is now archived and is closed to further replies.


Warning: fsockopen() [function.fsockopen]: unable to connect to ...

Recommended Posts


I've been using the sourceforge project phpffl (great project if you are into fantasy football) to set up a fantasy football league for my friends and have run into a kind of odd php problem.  The guys over at phpffl tried to help but gave me a test to determine if it was just phpffl or php in general and it looks like php in general so here I am...

Here's the scoop:
there is a update that is run to get player stats for scoring (statistics.php).  If I run a cron job that runs this file (php /pathname/statistics.php > stats.out) (the redirect is just so I can see some results, actual updating is in a mysql database), it works fine.

If I run the file from the browser (which the guys at phpffl says should work), a la

it doesn't work.  I get a sort of empty set results.  Turning on more error handling for php reveals the following error:
Warning: fsockopen() [function.fsockopen]: unable to connect to myffl.net:80 (Permission denied) in /var/www/html/ffl/program_files/autorun/myffl/functions/statistics_functions.php on line 55

Now, why isn't this a phpffl problem?  Well, I created the following file in the same directory:
ini_set("display_errors", "On");

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

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

I get the same error:
Warning: fsockopen() [function.fsockopen]: unable to connect to www.google.com:80 (Permission denied) in /var/www/html/ffl/program_files/autorun/myffl/test.php on line 4
Permission denied (13)

So I guess php isn't being allowed to open a connection.  I'm pretty new to fooling with php but have some knowledge about stuff otherwise.

Oh, I'm running Fedora Core 5 with pretty standard firewall/SELinux settings (ports open for HTTP, SSH, mail, TS) behind a consumer wireless router.

Thanks for any help you can give me.


Share this post

Link to post
Share on other sites
You'll want to look in your php.ini for [i]allow_url_fopen[/i], make sure it is switched to On.

Share this post

Link to post
Share on other sites
Thanks for the suggestion.  Didn't see your reply for awhile.  New to phpfreaks.com and didn't realize that it doesn't auto-notify.
allow_url_fopen is on.  Any other suggestions?  Here is that section of my php.ini file.

; Fopen wrappers ;

; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
allow_url_fopen = On

; Define the anonymous ftp password (your email address)

; Define the User-Agent string
; user_agent="PHP"

; Default timeout for socket based streams (seconds)
default_socket_timeout = 60

; If your scripts have to deal with files from Macintosh systems,
; or you are running on a Mac and need to deal with files from
; unix or win32 systems, setting this flag will cause PHP to
; automatically detect the EOL character in those files so that
; fgets() and file() will work regardless of the source of the file.
; auto_detect_line_endings = Off


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.