there are many questions on this topic, but I couldn't find an answer to my scenario.
The client project I am working on is hosted on a server running PHP 4.3.9 and I am trying to copy a remote image to the server. This always fails with a timeout:
var_dump(
copy('http://domain.com/path/to/image.jpg',
'/opt/www/myfolder/myimage.jpg')
);
The error message for this being: Warning: copy(http://domain.com/path/to/image.jpg): failed to open stream: Connection timed out in /opt/www/myfolder/my-script.php on line xx bool(false)
I did a trace of several ini settings, which would seem fine to me.
var_dump(
ini_get('upload_max_filesize'),
ini_get('post_max_size'),
ini_get('max_execution_time'),
ini_get('max_input_time'),
ini_get('allow_url_fopen'));
This traces:
string(2) "8M" string(2) "8M" string(2) "30" string(2) "60" string(1) "1"
So allow_url_fopen
seems to be enabled, and the other settings seems fine too. I tried different images, all accessible via browser, all with small sizes, different remote hosts. My server's target directory is writable and copying for example a file from my own server's URI copies the file just fine.
I also tried a curl
variant from this answer, with same result.
When I try the same script on a different server with newer PHP version it works fine.
What setting on the project server can cause this to fail? Is there something about PHP 4.3.9 I am missing that causes this to fail?
Please, please note that I cannot change the PHP version and I have no need for answers advising me to upgrade or convince my client to upgrade
Edit: Changed upload_max_filesize
to 40MB and max_execution_time
to 600 with no different result.
As pointed out by @Charles and @SalmanA in the comments, there seems to be a connectivity problem on the server preventing the copy calls.
Based on @SalmanA's comment, trying to use wget
from the ssh shell showed a similar timeout result, indicating a blocked connection.
Contacting the server host and inquiring further is the solution here.