Jump to content

prevent a 503 error in soap request


spiderwell

Recommended Posts

Hi all,

I hope you can help me out on this one, I am writing a class that uses soap to fetch data from a server but it gives me a 503 error when the server is not reachable, I am trying to catch it but it doesnt seem to be working:

here is what I have so far, please note that i havent not put in the rest of the class so assume the rest is all good below the __construct() method as it is :)

when the service is working and the SOAP errors are getting caught fine with this code, but the Service Unavailable i suspect cannot be caught? Is there another way i can approach this to achieve the same goal?

 

class Khaos_model extends CI_Model {

   public $clientUrl = "https://999.999.999.999/censored.exe/";//obviously changed for forum
   public $client = false;
   public $connection = false;
   public $connectionerror = false;
   public function __construct()
   {
	    parent::__construct();
	    try {
					    $this->client = new SoapClient($this->clientUrl);
					    $this->connection = true;
		    }
	   catch (SoapFault $fault) {
					    $this->connectionerror = "SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})";
		    }
   //    
   }

 

Many Thanks

Link to comment
https://forums.phpfreaks.com/topic/272711-prevent-a-503-error-in-soap-request/
Share on other sites

with a slight adjustment

$this->client = new SoapClient($this->clientUrl, array('exceptions' => true));

but i am not on 5.4, i have 5.3 and it still does the same thing :( gives

 

 

A PHP Error was encountered

 

Severity: Warning

Message: SoapClient::SoapClient(https://999.999.999.999/censored.exe/) [soapclient.soapclient]: failed to open stream: HTTP request failed! HTTP/1.1 503 Service Unavailable

Filename: models/khaos_model.php

Line Number: 13

I also should have asked if 503 throws an error. Exceptions are thrown when there is a SoapClient error not if there's an HTTP 503 response.

 

Are you trying to reach a wsdl file or something else? And why are you concerned about handling the error as opposed to finding out why its giving a 503 response? Are you doing this on purpose?

its for a website that has a shop, and i have to check stock levels on checkout, and to do that i have to use SOAP to contact the service, if the service is unavailable I want to be able to display a friendly message not have the 503 response which is what i get if i try and make the soap connection when the server is unreachable. I am trying to find a way to avoid this so that the website doesnt look like it has crashed because i cannot reach the remote server via SOAP.

Yes I am trying to reach WSDL, the client URL is like this: 'https://999.999.999.999/censored.exe/wsdl/IKosWeb', I should have put that in from the start, my apologies, I didnt realise that part was important, my SOAP knowledge is not up to much sadly.

The soap exceptions are caught by my code, its just when i try and create the soapClient and the server is unreachable that it doesnt get caught. I am doing this on purpose as I want to be able to cover the situation should it arise.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.