A PHP program access a website timout - php

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

Related

simplexml_load_file failed to open stream: Connection timed out

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."

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.

Wolfram Alpha php implementation issue

I am trying to implement Wolfram Alpha API to my application. I download their language library and load their sample page in my browser.
However, I got
Warning: simplexml_load_file(http://api.wolframalpha.com/v1/query.jsp?appid=myid-8RJR4ELL82&input=pi): 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\wolfram\PHP_Binding_0_1\wa_wrapper\WolframAlphaEngine.php on line 47
Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://api.wolframalpha.com/v1/query.jsp?appid=myid-8RJR4ELL82&input=pi" in C:\xampp\htdocs\wolfram\PHP_Binding_0_1\wa_wrapper\WolframAlphaEngine.php on line 47
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\wolfram\PHP_Binding_0_1\wa_wrapper\WolframAlphaEngine.php on line 47
I use their premade PHP library and load
http://localhost/wolfram/PHP_Binding_0_1/samples/simpleRequest.php?q=pi
in my address bar.
Can anyone help me about this issue? Thanks a lot!
Maximum execution time of 30 seconds exceeded
Set the request timeout to a number greater than 30 seconds or get a better internet connection.
You can do this by the following:
set_time_limit
set_time_limit(120); // two minutes
or if you are using a CURL request:
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
Alternatively, call up your internet provider and ask to upgrade your data plan to a higher number of mb/s.
It would also help to post you code. The mentioned methods of fixing this are based on the error, which could be resultant of a separate problem.

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