Jump to content

Include error: connection refused


Confusion101

Recommended Posts

A piece of my code performs scheduling by using a ./board/scheduler.php to get urls from a database and than including those url's.

e.g.: include($event); where $event might contain "http://www.example.com/board/deletepost.php?poster=me&post=yesterday"

This used to work fine for the longest time, until I started receiving this error:

 

Error: [2] include(http://www.example.com/board/deletepost.php?poster=me&post=yesterday) [<a href='function.include'>function.include</a>]: failed to open stream: Connection refused in /usr/www/www.example.com/board/deletepost.php on line 46

 

The &amp is an ampersand in the code for sure. Somehow it gets changed in the errorlog procedure.

Also I tried to put a php.ini file in the root and the board directory to ensure that allow_url_fopen was on.

Then I tried to add the following:

 

ini_set("include_path",".;http://www.example.com/board");

ini_set("allow_url_fopen","On");

 

Could anyone explain what's going wrong and how to fix it?

 

 

Link to comment
Share on other sites

Ok, I tried to turn it on in the php.ini file and I tried to add ini_set("allow_url_include","On"); inline, but neither worked.

A strange thing I noticed was that even though I added php.ini to in both www.example.com and the board directory, when I run phpinfo (from either directory) it seems as if the settings are unchanged, both local and master value are the same, but not the value I gave it in the php.ini file?

 

For completion:

The server is Apache/1.3.37 (Unix)  running PHP/5.1.5

Link to comment
Share on other sites

Thanks. I don't seem to have access. I'll contact the one who should have.

Nevertheless doesn't php first look at the php.ini file in the directory of the file that's being executed?

Also shouldn't ini_set's change something.

Finally and most importantly, despite some mentions about an earlier version, allow_url_include isn't

introduced until php 5.2 and I'm running 5.1.5. I've verified that allow_url_fopen is on, so the problem

should be elsewhere. Any ideas anyone?

Link to comment
Share on other sites

"Connection refused in /usr/www/www.example.com/board/deletepost.php on line 46"

 

This is talking about an error in deletepost.php, not in your scheduler.

 

Also, it's very strange to use include() to call a script using a URL.  include() is usually for local files.  CURL or file_get_contents() would make more sense.

Link to comment
Share on other sites

A few things.

 

First and foremost, this is a bad idea.  I don't think you should include from a remote server.  However, if you insist, please be aware:

 

re: allow_url_fopen

Note:  This setting can only be set in php.ini due to security reasons.

 

http://ca.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen

 

ini_set() has a return value (false on failure).  Because not all ini values can be set using ini_set and because security settings may prohibit certain changes, you ought to check the return value of ini_set() rather than assuming it will succeed.

 

You should examine the error you are getting closely:

 

failed to open stream: Connection refused in /usr/www/www.example.com/board/deletepost.php on line 46

 

Connection refused means your connection is not accepted by the remote host.  I think you need to fix the server, not the client.

 

Finally, please note that this is non-portable code:

 

ini_set("include_path",".;http://www.example.com/board");

 

The correct form is:

 

ini_set('include_path', '.' . PATH_SEPARATOR . 'http://www.example.com/board');

 

Link to comment
Share on other sites

Thanks for the replies. First of all I messed up; The error was:

 

Error: [2] include(http://www.example.com/board/deletepost.php?poster=me&post=yesterday) [<a href='function.include'>function.include</a>]: failed to open stream: Connection refused in /usr/www/www.example.com/board/scheduler.php on line 47

 

The error was generated in the scheduler. The reason for using include here is to run the the code of deletepost (which is on the same server) with specific parameters, without actually including any of it's methods. If you look at the specifications of include you'll see the difference between including an url and including a file.

 

I am indeed unable to change the configuration, but get_cfg_var on allow_url_fopen and allow_url_include return 1 and nothing at all respectivaly. Thus allow_url_fopen is on and allow_url_include is not in place in php 1.5.1. Those settings should thus not be the culprit.

 

I'm recoding the whole bunch, so that I no longer have to rely on this construction, but I'd still like to learn why it's failing, especially since it used to work.

Link to comment
Share on other sites

The error was generated in the scheduler. The reason for using include here is to run the the code of deletepost (which is on the same server) with specific parameters, without actually including any of it's methods. If you look at the specifications of include you'll see the difference between including an url and including a file.

 

I do not understand "run the code ... without actually including any of it's [sic] methods".  I do not understand why you need to use include() to obtain a file on the same server.  I also would expect that the web server would provide the output of deletepost.php rather than its code if you access it by URL.

 

You could provide parameters to a file include() by defining variables prior to but within the same scope as the include() function call.

 

 

I'm recoding the whole bunch, so that I no longer have to rely on this construction, but I'd still like to learn why it's failing, especially since it used to work.

 

As I previously posted, "connection refused" is an indication that the server (Apache?) is refusing the in-bound connection.  This is not a problem with the client (the PHP script) per se.  I do not know why the server is refusing the connection.  Were I the programmer, I would use the Live HTTP Headers extension to Firefox to examine the request and response in greater depth.  I'd confirm that the server is bound to port 80.

Link to comment
Share on other sites

Oh, based on your use of a semi-colon in the include_path, I suppose you're actually using IIS.  In any event, though, the same theory applies.  Verify that it is bound to port 80.  Try navigating to that URL with your browser.  Do you successfully connect and see output?

Link to comment
Share on other sites

According to phpinfo() I'm running "Apache/1.3.37 (Unix)". The server_port is 80 and I can manually navigate that page or normally include it (i.e. include("deletepost.php")), I just can't URL include it.

 

I'd like to see your phpinfo() output.  It seems this is a server configuration issue either in Apache or PHP.

 

 

Link to comment
Share on other sites

 

The error was generated in the scheduler. The reason for using include here is to run the the code of deletepost (which is on the same server) with specific parameters, without actually including any of it's methods. If you look at the specifications of include you'll see the difference between including an url and including a file.

 

You should use readfile() instead, as suggested in the manual:

 

http://sg.php.net/manual/en/function.include.php

 

But I don't expect that will fix the error.  If you're familiar with curl, try connecting to the URL using that and see what happens.  "Connection refused" indicates that php can't connect to the webserver.

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.