simplexml_load_file failed to open stream: Connection timed out - php

This page of my site is taking 1 minute to load. Then I got this error:
"Warning:
simplexml_load_file(http://www.cpalead.com/dashboard/reports/campaign_rss.php?id=MyID&geoip=MyIP&show=6&offer_type=pinsubmit):
failed to open stream: Connection timed out in ../pass/pass.php on
line 125 Warning: simplexml_load_file()"
My code:
$call_url = 'http://www.cpalead.com/dashboard/reports/campaign_rss.php?id='.$user_id.'&geoip='.$ip.'&show=6'.'&offer_type=pinsubmit';
if($xml = simplexml_load_file($call_url, "SimpleXMLElement", LIBXML_NOCDATA))
What I've tried to fix that and didn't work:
Switch allow_url_fopen to ON in php.ini of my hosting.
set the max time out to 300 second instead of 120.

It's because the website has blocked your server, after they got too many requests from your server.
There is no solution until they unblock you voluntarily or upon your request (I am not sure they have a way to do that). But if you can move to another server, that can work, until they block that server also!
Golden rule is "Don't make too many requests to any specific site unless they have allowed you to do that by terms."

Related

A PHP program access a website timout

My PHP program access a website which is very slow to open, therefore I get a warning message:
Warning: file_get_contents(http://www.example.com): failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\mezi.php on line 155.
Line 155 code: $html = file_get_contents('http://www.example.com');
My question is: how to increase time allowed to wait for slow website? I have already increased allowed execution time by adding set_time_limit(100); to my code. But this does not help.
This is actually a socket session that's being created behind the scenes, therefore the correct value in php.ini would actually be
default_socket_timeout

File_get_content . Failed to open a stream

I am a PHP apprentice. And I have a problem I can not solve with my meager knowledge. Indeed, I want to open a page just by submitting my form. And every time I receive this message: "failed to open stream: A connection attempt failed because the connected party did not properly......". Would there be a reason for that? I remind you that I am fairly new to the language. This is my code :
My "You page" :
<?php
$query=file_get_contents('https://www.youtube.com/watch?v=SrqDqqy8Yok');
echo($query);
?>
And my form is just calling this page.
This is the entire answer when i want to submit my form :
Warning: file_get_contents(http://www.youtube.com/watch?v=XiFrfeJ8dKM): failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\stpnet\You.php on line 2
pretty sure that it is an firewall problem. I have testet your code and it's working for me.
Or maybe you can try to set the allow_url_fopen in the php.ini file (but that would be another error message).
try to follow this code hopefully it will work.
$query= file_get_contents("https://www.youtube.com/watch?v=SrqDqqy8Yok",true)

Warning: file_get_contents failed to open stream: Connection timed out in includes/simple_html_dom.php on line 75

All of a sudden my cronjob has stopped working properly where it grabs content through file_get_contents and started giving the following warning and fatal error. Does anyone know why it is doing this?:
Warning: file_get_contents(http://seriesgate.me/search/indv_episodes/The+Social+Network): failed to open stream: Connection timed out in includes/simple_html_dom.php on line 75
Fatal error: Call to a member function find() on a non-object in includes/seriesgate.class.php on line 25
Its working.
echo file_get_contents("http://seriesgate.me/search/indv_episodes/The+Social+Network");
It may be execution problem.
Try this
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
echo file_get_contents("http://seriesgate.me/search/indv_episodes/The+Social+Network");
The Connection timed out error is a network problem for sure.
First, that's maybe your network connection problem take too long to get response from server. Please check your local/server/hosting internet connection; domain name, IP, port,... typo.
Secondly, that's maybe destination problem. For example, seriesgate.me is down for everyone, not only you. I know this question is 3 years old and the site is down. But this is best practice that you should check your destination when it's say something like Connection timed out.

Identifying root cause of a timeout in PHP

A little while ago I noticed some Soap errors emitting from my app and I started to investigate them. Stuff like:
SoapClient::SoapClient(http://###.###.###.###:8080/path/to/some.wsdl): failed to open stream: HTTP request failed!
SoapClient::SoapClient(): I/O warning : failed to load external entity "http://###.###.###.###:8080/path/to/some.wsdl"
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://###.###.###.###:8080/path/to/some.wsdl' : failed to load external entity "http://###.###.###.###:8080/path/to/some.wsdl"
It looked like a timeout on the remote server (WSDL caching was turned off). After bouncing that server and having no luck, I tried to just file_get-contents() the WSDL to see what would happen...
No dice: After about 20 seconds or so I got the same stream error:
file_get_contents(http://###.###.###.###:8080/path/to/some.wsdl) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed!
In a last ditch effort, I tried to read the contents via the curl_* functions, and I do in fact get what I'm looking for.
... tl;dr?
SoapClient and file_get_contents appear to be timing out (though not an explicit "Failed to open stream, connection timed out")
It appears to be related to streams since curl gives me what I'm looking for.
I've got a lot of code that depends on SoapClient and file_get_contents so switching to an all curl solution isn't really an option.
This is not a DNS issue as I can resolve external names fine (and my target resource is an IP)
allow_url_fopen is enabled.
Any ideas?
allow_url_fopen needs to be On in your PHP settings for file_get_contents to work with URLs. It'll give you that exact error otherwise. Double-check your PHP settings by loading a page with a phpinfo(); call to make sure they're not being overridden by a different php.ini or .htaccess file.
I'd guess a firewall problem otherwise but you say curl works from inside PHP, which would be opening sockets in the same manner.

PHP fopen() failed in combination session_start() and mysql_connect()

We have a problem on Debian server and PHP version 4.4.4-8+etch6. In this script (it is full script, not just part of code):
mysql_connect('localhost', 'user', 'pass');
session_start();
$h = fopen('http://www.google.com/robots.txt', 'r');
var_dump(fread($h, 40));
If I comment out mysql_connect, it works. If i comment out session_start, it works.
If mysql_connect failed (bad user and password) fopen works too. But with both, fopen failed. So it is not related to DNS lookup.
There is a result
Warning: fopen(http://www.google.com/robots.txt) [function.fopen]: failed to open stream: HTTP request failed! in /var/www/web4/rychtarka.cz/rychtarka.cz/test.php on line 9
Warning: fread(): supplied argument is not a valid stream resource in /var/www/web4/rychtarka.cz/rychtarka.cz/test.php on line 10
bool(false)
I think, there is some resources limit in system, file descriptors or something. Our server administrator told us, it is skript error. Can you please point me to debian system change to repair.
Thank you for any advice.
Finally (after 3 days) we fixed the error. We traced it using 'php -f test.php' which pointed to Apache's limit on max open files.
We raised number via ulimit from 1024 to 8k and after a restart everything worked great.

Categories