I am working on a PHP script that's processing a lot of data through a SOAP connection. Estimates of the total run time of the script look to be several days if it doesn't encounter any errors. The problem I'm running into is the script will run for a while, anywhere from an hour to a day, and then the SOAP connection will die with the error "error fetching http headers".
I've seen many articles suggesting increasing the default_socket_timeout setting and I've tried this. It hasn't helped. I know it's working cause it makes at least a hundred successful calls before it fails. Is there anything i can do to stop this error?
Update
I printed out the request and response headers hoping to see an error in there. But it appears they are fine:
HTTP/1.1 200 OK
Date: Wed, 25 Sep 2013 21:00:12 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Content-Length: 516
Connection: close
Content-Type: text/xml; charset=UTF-8
as far as example code goes the actual script is crazy long, but the basic premise is this:
ini_set('default_socket_timeout', 120);
$client = new SoapClient($wsdl,array(
'trace' =>true,
'connection_timeout' => 500000,
'cache_wsdl' => WSDL_CACHE_BOTH,
'keep_alive' => true,
));
while(!$finished) {
$finished = $client->someSoapFunction($data);
}
someSoapFunction() will return valid data for 100 of connections and then randomly return me the above error. The time it runs for is less than either of the set timeouts. I'm getting no errors in my php or apache error logs. I'm stumped.
I know it is an old question, but perhaps my solution can be useful to others.
I had the same problem and by changing the 'keep_alive' parameter to false in the creation of the SoapClient object, my problem was solved:
$client = new SoapClient($wsdl,array(
'trace' =>true,
'connection_timeout' => 500000,
'cache_wsdl' => WSDL_CACHE_BOTH,
'keep_alive' => false,
));
Related
So I'm trying to send a message to a chrome extension through GCM, using php.
$data = json_encode(array(
'channelId' => 'channel id here',
'subchannelId' => '0',
'payload'=>'test'
));
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => "https://www.googleapis.com/gcm_for_chrome/v1/messages",
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $access_token,
'Content-Type: application/json'
)
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
Each request returns { "error": { "code": 500, "message": null } }.
Thanks.
500 is the HTTP error code for internal error.
Sending a Google Cloud Message for Chrome from the Google oauthplayground website returns this for me:
HTTP/1.1 500 Internal Server Error
Content-length: 52
X-xss-protection: 1; mode=block
X-content-type-options: nosniff
X-google-cache-control: remote-fetch
-content-encoding: gzip
Server: GSE
Reason: Internal Server Error
Via: HTTP/1.1 GWA
Cache-control: private, max-age=0
Date: Wed, 15 May 2013 07:01:40 GMT
X-frame-options: SAMEORIGIN
Content-type: application/json; charset=UTF-8
Expires: Wed, 15 May 2013 07:01:40 GMT
{
"error": {
"code": 500,
"message": null
}
}
According to Google's Cloud Message for Chrome docs:
An internal error has occurred. This indicates something went wrong on the Google server side (for example, some backend not working or errors in the HTTP post such as a missing access token).
Essentially there's something wrong on Google's side of things. Considering Google I/O is going to start in a few hours I would assume they're currently making some changes.
Try checking again in a few hours.
I ran into the same problem today.
I found an issue tracker on the Chromium Apps group
https://groups.google.com/a/chromium.org/forum/?fromgroups=#!topic/chromium-apps/UXE_ASCN0gc
One of the possible reasons for that is if the app you use for testing was never published in the Chrome Web Store. So if you created an app locally and load it into Chrome unpackaged for testing for example - it will always fail like this because GCM does not know who owns the app. When publishing the app to the Store, use the same google account that was used in Api Console to create a project and Oauth clientId/client secret etc. The GCM for Chrome works only if those google accounts match.
GCM verifies the owner of an app matches the owner of an access token to make sure nobody but owner of an app publishes messages for it. Publishing the app in the Web Store creates a link between a google account and the appID so it can be verified.
Now, once you publish some version of your app, you can add the magic token generated by Web Store to the manifest of your local app and continue modify/reload/debug locally, now having your app correctly registered for GCM. See my answer in chromium-apps group for more details on that.
I got the same error too. I resolved this by packaging my app and upload to chrome webstore. Then I use new Channel ID and it works now
I've downloaded Amazon's Marketplace SDK and I'm trying out one of the samples in the samples dir. However, I'm getting an exception with the following details whenever I try it:
Caught Exception: Internal Error
Response Status Code: 0
Error Code:
Error Type:
Request ID:
XML: RequestId: , ResponseContext: , Timestamp:
ResponseHeaderMetadata:
I have got CURL enabled with SSL as well. What am I doing wrong?
This answer is for future reference. For in-depth troubleshooting, see comments on the question.
The empty response indicates a failed connection to the Amazon server. In this case, HTTP worked fine, but HTTPS did not. As turning off CURLOPT_SSL_VERIFYPEER in the cURL settings solved the issue, it appears that the Amazon server was not using a valid SSL certificate.
Having CURLOPT_SSL_VERIFYPEER turned on checks if the requested host has a valid certificate and lets cURL return false if it doesn't. When CURLOPT_SSL_VERIFYPEER is off, invalid certificates (e.g., self-signed) are accepted and return the regular response.
For future reference. In the new version of the SDK the options are referenced in the client.php as follows
private function getDefaultCurlOptions() {
return array (
CURLOPT_POST => true,
CURLOPT_USERAGENT => $this->config['UserAgent'],
CURLOPT_VERBOSE => true,
CURLOPT_HEADERFUNCTION => array ($this, 'headerCallback'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2
);
}
setting
CURLOPT_SSL_VERIFYPEER => false,
did the trick in my case. As I am not a security expert, however, no recommendation from this point of view. At least its working and you are probably not loosing 1 whole day as I did.
I experienced a very similar connection issue with Amazon. It was the sample files bundled with the Amazon php api, which contain a following configuration array:
$config = array (
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'MaxErrorRetry' => 3,
);
and if this is copied over and not modified
'ProxyPort' => -1,
will result in an attempt to connect through a proxy port -1 which will of course fail (issue tracked by checking curl error). I hope this helps.
Morning all
Basically, I am unable to make successful cURL requests to internal and external servers from my Windows 7 development PC because of an issue involving a proxy server. I'm running cURL 7.21.2 thru PHP 5.3.6 on Apache 2.4.
Here's a most basic request that fails:
<?php
$curl = curl_init('http://www.google.com');
$log_file = fopen(sys_get_temp_dir() . 'curl.log', 'w');
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_VERBOSE => TRUE,
CURLOPT_HEADER => TRUE,
CURLOPT_STDERR => $log_file,
));
$response = curl_exec($curl);
#fclose($log_file);
print "<pre>{$response}";
The following (complete) response is received.
HTTP/1.1 400 Bad Request
Date: Thu, 06 Sep 2012 17:12:58 GMT
Content-Length: 171
Content-Type: text/html
Server: IronPort httpd/1.1
Error response
Error code 400.
Message: Bad Request.
Reason: None.
The log file generated by cURL contains the following.
* About to connect() to proxy usushproxy01.unistudios.com port 7070 (#0)
* Trying 216.178.96.20... * connected
* Connected to usushproxy01.unistudios.com (216.178.96.20) port 7070 (#0)
> GET http://www.google.com HTTP/1.1
Host: www.google.com
Accept: */*
Proxy-Connection: Keep-Alive
< HTTP/1.1 400 Bad Request
< Date: Thu, 06 Sep 2012 17:12:58 GMT
< Content-Length: 171
< Content-Type: text/html
< Server: IronPort httpd/1.1
<
* Connection #0 to host usushproxy01.unistudios.com left intact
Explicitly stating the proxy and user credentials, as in the following, makes no difference: the response is always the same.
<?php
$curl = curl_init('http://www.google.com');
$log_file = fopen(sys_get_temp_dir() . 'curl.log', 'w');
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_VERBOSE => TRUE,
CURLOPT_HEADER => TRUE,
CURLOPT_STDERR => $log_file,
CURLOPT_PROXY => 'http://usushproxy01.unistudios.com:7070',
CURLOPT_PROXYUSERPWD => '<username>:<password>',
));
$response = curl_exec($curl);
#fclose($log_file);
print "<pre>{$response}";
I was surprised to see an absolute URL in the request line ('GET ...'), but I think that's fine when dealing with proxy servers - according to the HTTP spec.
I've tried all sorts of combinations of options - including sending a user-agent, following this and that, etc, etc - having been through Stack Overflow questions, and other sites, but all requests end in the same response.
The same problem occurs if I run the script on the command line, so it can't be an Apache issue, right?
If I make a request using cURL from a Linux box on the same network, I don't experience a problem.
It's the "Bad Request" thing that's puzzling me: what on earth is wrong with my request? Do you have any idea why I may be experiencing this problem? A Windows thing? A bug in the version of PHP/cURL I'm using?
Any help very gratefully received. Many thanks.
You might be looking at an issue between cURL (different versions between Windows and Linux) and your IronPort version. In IronPort documentation:
Fixed: Web Proxy uses the Proxy-Connection header instead of the
Connection header, causing problems with some user agents
Previously, the Web Proxy used the Proxy-Connection header instead of the
Connection header when communicating with user agents with explicit
forward requests. Because of this, some user agents, such as Real
Player, did not work as expected. This no longer occurs. Now, the Web
Proxy replies to the client using the Connection header in addition to
the Proxy-Connection header. [Defect ID: 46515]
Try removing the Proxy-Connection (or add a Connection) header and see whether this solves the problem.
Also, you might want to compare the cURL logs between Windows and Linux hosts.
While initiating a PHP SOAP client webservice I get these errors in production.
Here is the line of code which generates the error:
//the php soap server is at different server
$client = new SoapClient(SITE_ROOT . "locally hosted wsdl",
array("trace" => 1, "exception" => 1));
The error being generated is:
ERRNO: 2 \nTEXT: SoapClient::__doRequest() [<a href='soapclient.--dorequest'>soapclient.--dorequest</a>]: SSL: connection timeout \nLOCATION:
So these errors only occur in production and occur 2-3 % of the total requests.
Also this is a PHP SOAP over HTTPS webservice, also the server hosting the webservice has firewall but all our frontend servers have access through the firewall.
Also the default_socket_timeout is set to 60 secs and max execution time is 30 seconds.
My question:
I want to know why this is happening.
Try this:
$client=new SoapClient(
SITE_ROOT."your/wsdl.here.wsdl",
array(
"exceptions" => true,
"connection_timeout" => 60,
"style" => SOAP_RPC,
"use" => SOAP_ENCODED,
)
);
$mxResponse=$client->__soapCall(
"someFunctionName",
array("params", "here")
);
I'm accessing a remote SOAP Service that tends to be reacting very slow from time to time (we're talking about more than 10 seconds here).
System is PHP Version 5.3.1, running on Windows Server 2003.
My client is set up like this:
new SoapClient($wsdl, array("trace" => true, "exceptions" => true, "cache_wsdl" => WSDL_CACHE_BOTH, "connection_timeout"=>5000));
Now when I'm shooting a request that takes more than about 10 seconds, the following happens: I get the late but correct response from the service, together with a 200 header (taken from SoapClient::__getLastResponse)
Response Headers:
HTTP/1.1 200 OK Via: 1.1 XXX Connection: Keep-Alive Proxy-Connection: Keep-Alive Content-Length: 430 Date: Mon, 10 Oct 2011 16:03:15 GMT Content-Type: text/xml;charset=UTF-8 Server: Microsoft-IIS/7.5 X-Powered-By: Servlet 2.5; JBoss-5.0/JBossWeb-2.1 X-Powered-By: ASP.NET
But as the SOAP result, I get a SoapFault:
fault:
code: 500
message: An internal error occurred. Please contact our support.
I've tried preventing this with:
ini_set('default_socket_timeout', 5000 );
and setting up the SoapClient with "connection_timeout"=>5000 as seen above. Nothing helps. Any suggestions would be heavily appreciated.
Just had the same problem while accessing a Web Service in SAP and it was not a PHP Bug but a timeout setting in the SAP Web Dispatcher.
I was fighting this for many hours trying to figure out what was wrong with PHP or the SOAP Module.
Finally, I tested in SOAP-UI and the problem was solved quickly. You should do the same with SOAP-UI. Perhaps the Webservice you are calling is depending on another remote connection that has its own timeout settings.