nusoap error : HTTP Error: socket read of headers timed out - php

i need a help
i have a problem in using nusoap for PHP when client want to access service in server
the error is :
HTTP Error: socket read of headers timed out
this is my XML can be accessed at [http://sobath-market.com/index.wsdl.php?wsdl][1]
can someone help me??
thanks

Instead of changing the "nusoap.php" file you can call the constructor passing the timeout as a parameter.
$client = new nusoap_client(
/*endpoint*/ $url,
/*wsdl*/ $type,
/*proxyhost*/ false,
/*proxyport*/ false,
/*proxyusername*/ false,
/*proxypassword*/ false,
/*timeout*/ $timeout, //here you can define timeout
/*response_timeout*/ $responseTimeout, //here is what you want to define
/*portName*/ '');

Hi this error often occurs for a new user who using nusoap , as the default response time has been to 30 seconds. As of your request exceeds more than this execution time, you are getting this error, to fix this issue change the following code in "nusoap.php" in your nusoap library
socket_set_timeout( $this->fp, $response_timeout);
to
socket_set_timeout( $this->fp, 200);
i hope you got the expected solution from this.

Related

Using https when calling waitFor method setting up openstack nova server

I have the following PHP script (this is just the bottom half):
use Guzzle\Http\Exception\BadResponseException;
$server = $compute->server();
try {
$response = $server->create(array(
'name' => 'My server',
'image' => $centos,
'flavor' => $twoGbFlavor
));
} catch (BadResponseException $e) {
// No! Something failed. Let's find out:
printf("Request: %s\n\nResponse: %s", $e->getRequest(), $e->getResponse());
}
use OpenCloud\Compute\Constants\ServerState;
$callback = function($server) {
if (!empty($server->error)) {
var_dump($server->error);
exit;
} else {
echo sprintf(
"Waiting on %s/%-12s %4s%%",
$server->name(),
$server->status(),
isset($server->progress) ? $server->progress : 0
);
}
};
$server->waitFor(ServerState::ACTIVE, 600, $callback);
When I run it I receive the following error:
PHP Fatal error: Uncaught exception 'Guzzle\Http\Exception\CurlException' with message '[curl] 52: Empty reply from server [url] http://api.openstack.ecloud.co.uk:8774/v2/b7db5fe13c044b6e95bf5b766ae49393/servers/f5bf8951-f662-4940-904c-023b98b724c0' in /var/www/html/nutshell/openstack/vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php:359
I have narrowed it down to a problem with the waitFor method using http instead https. However I am unable to work out how to get this method to use https or if there is a setting I can change to force all calls over https?
In addition I have tried running these commands using curl on the command line, outside of the script, and can confirm the https one works. So I just need to work out how to get the script call to use https.
Also, note the $server->create call above works fine and I would have just expected the waitFor to work in the same fashion (i.e. over https).
Any help would be much appreciated.
You created server with https, got response with server data. Server data contains self url and that url is most probably http.
"waitFor" is calling openstack for server data with that url. You can see this here:
https://github.com/rackspace/php-opencloud/blob/working/lib/OpenCloud/Common/Resource/BaseResource.php (line 148)

SoapClient call returns 500 Internal Server Error

I am trying to connect to an API using PHP and its built-in SoapClient. I have checked against the url I was given through the ill-formatted documents the client gave and $client->__getFunctions() returns a list of three functions. HelloWorld($name), which responds with Hello ~name~, shows me that I am communicating with the server through the SoapClient call and the URL is correct.
However, when I try to access one of the other methods that __getFunctions() gives me, even after copy/pasting the XML from the docs and putting in my own credentials, I am still being given an Internal Server Error faultstring and 500 as faultcode from the SoapFault object.
I am sure that it is my own XML string that is causing the issue but I cannot for the life of me figure out how. Reaching out to the API provider directly hasn't proven helpful. This is my first time dealing with Soap/Web Services so I am unsure of where to go from here.
I did wget http//xxx.xxx.xxx?wsdl and it returned me what looks like a valid XML response, the same one I get when I go directly to the url in the browser. What should I be looking into in order to solve this issue? All of the past API's I've dealt with have been JSON/RESTful so I feel out of my element trying to debug PHP errors.
Edit
I have slowly deleted parts of my method call and parts of my XML string, trying to trigger a different error or something in order to find what I need to fix. What I have found is that by not passing in my XML string, I get a valid response from the $client->FunctionCall(...). It's an "this isn't right" message but it's a message! In fact, passing that function ANYTHING for the xml parameter causes the 500 http faultcode/faultstring. Does this mean that my XMl is poorly formatted or does it mean that there is an issue on their end handling requests?
Second Edit
If I make my $client decleration as follows, I get the faultstring Could not connect to host
$opts = array(
'ssl' => array('ciphers'=>'RC4-SHA')
);
$client = new SoapClient($CREDS['orderingWSDL'], array (
"encoding"=>"ISO-8859-1",
'stream_context' => stream_context_create($opts),
'exceptions'=>true,
));
I am getting more confused the longer I try to fix this.
Sometimes a 500 status coming from a SOAP service could be a SoapFault exception being thrown. To help your troubleshooting, you'll want to be able to inspect both your request XML, and the response XML.
Put your code in try/catch blocks, and use $client->__getLastRequest() and $client->__getLastResponse() to inspect the actual XML.
Example:
$client = new SoapClient('http//xxx.xxx.xxx?wsdl', array('soap_version'=>SOAP_1_1,'trace' => 1,'exceptions' => true));
try {
$response = $client->someFunction();
var_dump($response);
} catch (Exception $e) {
var_dump($e->getMessage());
var_dump($client->__getLastRequest());
var_dump($client->__getLastResponse());
}

Previously working call to send SMS msg via TWILIO is now failing with... "Unsupported SSL context options are set."

This has been working fine for awhile and I haven't changed a thing. The code runs on Google AppEngine, which may have changed something in the past 12 hours that would cause this??
Here's the full error message:
HP Warning:
file_get_contents(https://api.twilio.com/2010-04-01/Accounts/AC3f5788e1bf9a85f308ed805dc57b1111/Messages.json):
failed to open stream: Unsupported SSL context options are set. The
following options are present, but have been ignored: cafile,
verify_depth Request deadline exceeded in
/base/data/home/apps/s~vivonoteapp/1.371473117917944991/twilio-php-master/Services/Twilio/HttpStream.php
on line 62
By the way, here is line 62 referenced above (no change since when it was working):
$result = file_get_contents($url, false, $ctx);
And here's my code that results in line 62 being called (no change since when it was working):
$sms = $client->account->messages->sendMessage(get_twilio_number(), // FROM
$sender, // TO
$msg);
Thanks for any thoughts.
Liz
The actual error is 'Request deadline exceeded', the other messages are warning which are letting you know that some of the SSL options you're supplying are not used by the URLFetch implementation.
You can try extending the deadline of the request by passing a larger timeout value in the http options that you pass to stream_context_create.
$options = [
'http' => [
'timeout' => 60.0,
],
];
Also, there was a URLFetch outage yesterday that might explain your problems as well. Details here.

PHP Get Content of HTTP 400 Response

I am using PHP with the Amazon Payments web service. I'm having problems with some of my requests. Amazon is returning an error as it should, however the way it goes about it is giving me problems.
Amazon returns XML data with a message about the error, but it also throws an HTTP 400 (or even 404 sometimes). This makes file_get_contents() throw an error right away and I have no way to get the content. I've tried using cURL also, but never got it to give me back a response.
I really need a way to get the XML returned regardless of HTTP status code. It has an important "message" element that gives me clues as to why my billing requests are failing.
Does anyone have a cURL example or otherwise that will allow me to do this? All my requests currently use file_get_contents() but I am not opposed to changing them. Everyone else seems to think cURL is the "right" way.
You have to define custom stream context (3rd argument of function file_get_contents) with ignore_errors option on.
As a follow-up to DoubleThink's post, here is a working example:
$url = 'http://whatever.com';
//Set stream options
$opts = array(
'http' => array('ignore_errors' => true)
);
//Create the stream context
$context = stream_context_create($opts);
//Open the file using the defined context
$file = file_get_contents($url, false, $context);

HTTP request failed! HTTP/1.1 505 HTTP Version Not Supported error

I'm trying to use file_get_contents() to get the response from a server and this error was encountered. Could someone tell me what is the reason and how to fix it? The portion of the code is:
$api = "http://smpp5.routesms.com:8080/bulksms/sendsms?username=$username&password=$password&source=$source&destination=$destin&dlr=$dlr&type=$type&message=$message";
$resp = file_get_contents($api);
The server responded correctly while I pasted the url in the browser.
I learned that this is caused by the server rejecting the client's HTTP version, but I have no idea why that is happening in my case.
Any help is much appreciated. Thanks in advance
I found the problem, and it was a simple coding error -- missing url encoding.
The reason I didn't notice it at first was because the code was ok before I did some editing, and I'd missed out the urlencode() function before calling the server, which caused a space in the url.
This does seem to be the reason this error occurs for most people. So if you encounter this, use urlencode() on all variables which may contain white space in it's value used as URL parameters. So in the case in my question the fixed code will look like:
$api = "http://smpp5.routesms.com:8080/bulksms/sendsms?username=$username&password=$password&source=$source&destination=$destin&dlr=$dlr&type=$type&message=" . urlencode($message);
$resp = file_get_contents($api);
Also, thanks for all of your time and responses, those were informational.
You could create a stream context with the HTTP version set to 1.0 and use that context with file_get_contents:
$options = array(
'http' => array(
'protocol_version' => '1.0',
'method' => 'GET'
)
);
$context = stream_context_create($options);
$api = "http://smpp5.routesms.com:8080/bulksms/sendsms?username=$username&password=$password&source=$source&destination=$destin&dlr=$dlr&type=$type&message=$message";
$resp = file_get_contents($api, false, $context);
By the way: Don’t forget to escape your URI argument values properly with urlencode.
I ran into the same issue and in my case the culprit was an errant newline/CRLF character at the end of the request URL, which does not get caught by urlencode() (or maybe it does encode it but it still causes the server to produce the error). Once I found the problem the requests began to work again, even without the stream context options.
Hopefully this will help others.
Can you sniff what's happening on the wire? Seeing the format of the HTTP request as it goes out on the wire would help a lot.
Without seeing that, my best guess would be that the server isn't well-implemented, and is rejecting a HTTP/1.1 request. Try setting --http1.0 on Curl and seeing what happens...
Some time we still get error with
file_get_contents($api);
in that case, try this:
fopen($api,"r");
I was also facing this same issue..
later i found that while retrieving the results from mysql, Limit $count ,
$count was -ve. fixing that the url worked fine.
There is some problem in url only, and its not a file_get_contents or http version issue..

Categories