/** * Process and return the results of an asyncrhonous SoftLayer API call * * Read data from our socket and process the raw SOAP result from the * SoapClient instance that made the asynchronous call. wait() * *must* be called in order to recieve the results from your API call. * * @return object */ public function wait() { $soapResult = ''; while (!feof($this->_socket)) { $soapResult .= fread($this->_socket, 8192); } // separate the SOAP result into headers and data. list($headers, $data) = explode("\r\n\r\n", $soapResult); return $this->_soapClient->handleAsyncResult($this->_functionName, $data); }
* account and connectivity. */ try { print_r($client->getObject()); } catch (\Exception $e) { die($e->getMessage()); } /** * For a more complex example we’ll retrieve a support ticket with id 123456 * along with the ticket’s updates, the user it’s assigned to, the servers * attached to it, and the datacenter those servers are in. We’ll retrieve our * extra information using a nested object mask. After we have the ticket we’ll * update it with the text ‘Hello!’. */ // Declare an API client to connect to the SoftLayer_Ticket API service. $client = SoapClient::getClient('SoftLayer_Ticket', 123456, $apiUsername, $apiKey); // Assign an object mask to our API client: $objectMask = new ObjectMask(); $objectMask->updates; $objectMask->assignedUser; $objectMask->attachedHardware->datacenter; $client->setObjectMask($objectMask); // Retrieve the ticket record. try { $ticket = $client->getObject(); print_r($ticket); } catch (\Exception $e) { die('Unable to retrieve ticket record: ' . $e->getMessage()); } // Now update the ticket. $update = new \stdClass();
/** * Process a SOAP request * * We've overwritten the PHP \SoapClient's __doRequest() to allow processing * asynchronous SOAP calls. If an asynchronous call was deected in the * __call() method then send processing to the * AsynchronousAction class. Otherwise use the * \SoapClient's built-in __doRequest() method. The results of this method * are sent back to __call() for post-processing. Asynchronous calls use * handleAsyncResult() to send he results of the call back to __call(). * * @return object */ public function __doRequest($request, $location, $action, $version, $one_way = false) { // Don't make a call if we already have an asynchronous result. if ($this->_asyncResult != null) { $result = $this->_asyncResult; unset($this->_asyncResult); return $result; } if ($this->oneWay == true) { $one_way = true; $this->oneWay = false; } // Use either the \SoapClient or AsynchronousAction // class to handle the call. if ($this->_asynchronous == false) { $result = parent::__doRequest($request, $location, $action, $version, $one_way); return $result; } else { $this->_asyncAction = new AsynchronousAction($this, $this->asyncFunctionName, $request, $location, $action); return ''; } }