How to fix Connection timed out, cURL error 28? - php

I bought a jobs portal script, I've successfully installed it and when I try to register I get this error:
cURL error 28: Connection timed out after 2013 milliseconds (see
http://curl.haxx.se/libcurl/c/libcurl-errors.html)
I asked support and they said:
you need to increase read_timeout and timeout. The error is clear, you
don’t have enough time to get the response. increase time in php.ini
I tried increasing max_execution_time, default_socket_timeout in php.ini both to 500, but I'm getting the same error. Then I tried manually adding read_timeout=500 and timeout=500 and again the same error.
What should I do?

CURLE_OPERATION_TIMEDOUT (28)
Operation timeout. The specified time-out period was reached according to the conditions
You can set the total time of the cURL transfer using:
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
Where 500 is the maximum number of seconds to allow cURL functions to execute.
Here is an example of initializing a new cURL session and fetching a web page:
<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
?>

Maybe you should enable stream_ socket_ server

Use the below mention in your curl request
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds

Related

Google App Engine (GAE) - PHP cURL Timeout being ignored

Look the following PHP code:
$start = time();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://gmaxil.com');
curl_setopt($ch, CURLOPT_USERAGENT, 'Java/1.7.0_60');
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
$end = time();
var_dump(curl_error($ch));
var_dump($end-$start);
curl_close($ch);
Running it on the local GAE environment (my machine), I get the following response (~2 seconds later):
string(43) "Resolving timed out after 2529 milliseconds" int(2)
Running it on GAE remote environment, I get the following response (~40 seconds later):
string(34) "Couldn't resolve host 'gmaxil.com'" int(40)
Why is Google App Engine ignoring the cURL timeout option?
Please check this link.
PHP cURL: CURLOPT_CONNECTTIMEOUT vs CURLOPT_TIMEOUT
CURLOPT_TIMEOUT is the maximum time that you allow the libcurl to transfer the data to server, this doesn't mean that the server is going to respond in the timeout that you set.

cURL error 28 - Connection timed out after x milliseconds

Yep. I know there is some alike questions about this err but i was read all of this and it not resolve my problem so:
My php code:
$url = 'example.domain.com/path/file.php'
$string = 'param=5';
$ch = curl_init();
// CURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Content-Length: ' . strlen($string)));
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
return curl_exec($ch);
I check errors this way:
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if($curl_errno > 0) {
echo "cURL Error ($curl_errno): $curl_error\n";
}
$curl_errorno is 28 and
curl_error is Connection timed out after 10001 milliseconds
Please help or get some clue what I can check.
from localhost or other server is it also working (curl or file_get_content)... is there any hint?
from local machine i get cURL ok response via php ~4sec
from server (host server) shell i get error 7 failed to connect to example.domain.com port 80: connection timed out
if in php try file_get_contents (from host server) - no response
URL - is accessible from browser (direct php file)
If i create ajax request - response is ok
If i trying add to url http or https - always same error
if i trying set limit to 30 sec. same result
I was having this problem, this is because the API you are trying to send the request does not accept the sending of many products at the same time. Then you need to put the PHP sleep function, so between each sent line a range is defined. Add sleep(seconds of interval); in your code.
You have to increase CURLOPT_TIMEOUT or remove timeout of cURL execution at all

PHP Curl - Send a ping (without waiting for the url to load fully)

I am trying to use curl to just give ping to a script.
Unfortunately, since this will run in a hosting where exec is disabled, I cant use exec to do the ping.
I was planning to use curl with a low time out. But thats Connection timeout, and since the connection is successful, it will wait till the page load is completed.
Code :
$ch=curl_init();
$timeout=1;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$result=curl_exec($ch);
curl_close($ch);
What I want to achieve is to ping to a page (its on my own domain, just another php script, if that helps) and not wait for the page load to complete.
Any advice guys?

Curl function not working in XAMPP 1.8.0

I am using Windows 7. I have installed XAMPP 1.8.0 and also enabled the CURL functionality. But, I am still not able to crawl web pages.
I used the following code segment:
<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.google.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
?>
And when I executed the program, the error message was:
Fatal error: Maximum execution time of 30 seconds exceeded in
C:\xampp\htdocs\testing\curl.php on line 14
Line 14: curl_close($ch)
Why I am getting such an error? How can I debug it? Please help me.
Add set_time_limit($seconds); in your page
also
add curl_setopt ($ch, CURLOPT_TIMEOUT, 60); and try

How to set a timeout on PHP5 curl calls? Published CURL options do not seem to work

We've written a script that pulls data from an external server. If the server goes down we don't want our server waiting for the data since we process a lot of data and we don't want it bogged down. To address this, we're trying to timeout our curl calls if they take more than a couple hundred milliseconds.
I found some documentation saying that CURLOPT_TIMEOUT_MS and CURLOPT_CONNECTTIMEOUT_MS should be available in my version of php and libcurl, but it does not seem to be timing out, even if I set the timeout to 1ms.
$url = "http://www.cnn.com;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER,0); //Change this to a 1 to return headers
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 1);
$data = curl_exec($ch);
curl_close($ch);
Does anyone know what we're doing wrong or another way to do this?
saw this in unresponsive dns server and curl multi timeouts not working:
"...We have had some times where a
site that we pull information has had
dns server become unresponsive. When
this happens the timeouts set in curl
(php bindings) do not work as
expected. It times out after 1min 14
sec with "Could not resolve host:
www.yahoo.com (Domain name not found)"
To make this happen in test env we
modify /etc/resolv.conf to have a
nameserver that does not exist
(nameserver 1.1.1.1). No mater what
they are set at
(CURLOPT_CONNECTTIMEOUT, CURLOPT_CONNECTTIMEOUT_MS
, CURLOPT_TIMEOUT, CURLOPT_TIMEOUT_MS)
they don't timeout when we cant get
to the DNS server. I use curl_multi
because i we have multiple sources
that we pull info from at the same
time. The example below makes one
call for example simplicity. And as a
side note curl_errno does not return
an error code even though there was an
error. Not sure why..."

Categories