Jump to content

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


khoffman22

Recommended Posts

Hi,

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
http://somename.com/path/statistics.php

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:
[code]<?php
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);
  }
  fclose($fp);
}
?>
[/code]

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.

Keith
Link to comment
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.

[code]
;;;;;;;;;;;;;;;;;;
; 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)
;from="john@doe.com"

; 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

:
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.