Jump to content

readfile() connection timeout external file


T-Bird

Recommended Posts

Alright,  I'm at a loss as to what my problem is.

 

I have a server box running Apache, PHP, and MySQL.  This box contians a php file called passfile.php with the following code.

 

<?php
include('inc/function.inc.php');
$file = verify_file($_GET['file']);
if($file != false)
{
	header('Content-type: application/octet-stream');
	header('Content-Disposition: attachment; filename="'.basename($file).'"');
	readfile('http://MyFileHostExternalIP:880/bids/plans'.$file);
}
else
{
	plans_error("<h3>Error: Requested File Not Found</h3>");
}
?>

 

This works great.  Now when I put this same php file, on my webhost and try to stream said file through my webpage to the user (so that I can better secure my files) I get the following error.

 

Warning:  readfile(http://MyFileServerExternalIP:880/bids/plans/ToC/a.txt) [function.readfile]: failed to open stream: Connection timed out in <b>/data/18/1/148/115/1800115/user/1948901/htdocs/estimating/passfile.php on line 8

 

Any ideas what I'm doing wrong.  Why can readfile access the file when launched from my local box, but not when launched from my webhost?  Is it an incorrect configuration?

Link to comment
Share on other sites

Most likely a permission error.

 

http://ca2.php.net/manual/en/function.readfile.php

Tip

A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename and List of Supported Protocols/Wrappers for a list of supported URL protocols.

 

Check your server php.ini and look for the allow_url_fopen setting.

Link to comment
Share on other sites

Yeah.  That was one of the first places I checked.

 

When I first posted I was sure it was a php error, however as I look at it I think it could possibly be an Apache configuration problem as well.  I'm lost on this one.

 

A readfile download doesn't use a seperate port I'd have to forward does it? Doesn't it go through whatever port I'm sending the rest of the page through?

Link to comment
Share on other sites

A readfile download doesn't use a seperate port I'd have to forward does it? Doesn't it go through whatever port I'm sending the rest of the page through?

I'm not sure. The only time I've loaded external files was through curl.

Link to comment
Share on other sites

If it at all helps anyone to grasp what's going on here, I drew a diagram.

 

diagram.bmp

 

The red path is the one that ultimately I will be using and that is not working.  The guest's node will connect to the passfile.php page of my webhost.  Passfile.php holds the previously mentioned code which attempts to connect to my fileserver via a direct ip address:port -  70.166.xxx.xxx:880.  It is supposed to use readfile() to make that connection and return the file contents from file.zip.  However it gives me a connection timeout error.

 

In blue was a test a ran to check the configuration status of my fileserver.  When the server locally runs passfile.php which is identical - including using a full external ip instead of an alias like localhost, the file is returned properly.

 

In green is a third test, where guest uses the fileserver's passfile.php to successfully retrieve file.zip.

 

In purple was a forth test, whereby the guest direct connects to file.zip  and successfully retrieves it.

 

In cyan is a fifth test where guest connects to passfile.php on the webhost which is using identical code to test one except the IP is changed to another server I rent from bluehost.

 

This is why I'm so baffled.  Test five shows it cannot be an error with the php configuration on my webhost - for example allow_url_fopen must be on as it allows me to retrieve the file from my other server.  It would seem to me that tests 2-4 indicate I have no leeching protection as both an arbitrary outside user as well as internal scripts both freely access the file.

 

I cannot fathom what the actual problem must be.  Any/all advice for further tests or fixes is gratefully accepted.

Link to comment
Share on other sites

  • 1 month later...

if i see correctly, you're connecting to port 880. try connecting to the standard port 80, i just tried with my networksolutions account, and i can successfully connect to port 80, but not for example to port 2222, which gives a timeout.

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.