Simaltaneous connections with PHP and SOAP?

Posted by Dov on Stack Overflow See other posts from Stack Overflow or by Dov
Published on 2011-01-09T17:48:00Z Indexed on 2011/01/09 17:54 UTC
Read the original article Hit count: 246

Filed under:
|
|
|

I'm new to using SOAP and understanding the utmost basics of it.

I create a client resource/connection, I then run some queries in a loop and I'm done. The issue I am having is when I increase the iterations of the loop, ie: from 100 to 1000, it seems to run out of memory and drops an internal server error.

How could I possibly run either a) multiple simaltaneous connections or b) create a connection, 100 iterations, close connection, create connection.. etc.
"a)" looks to be the better option but I have no clue as to how to get it up and running whilst keeping memory (I assume opening and closing connections) at a minimum.

Thanks in advance!

index.php

<?php
// set loops to 0
$loops = 0;

// connection credentials and settings
$location = 'https://theconsole.com/';
$wsdl = $location.'?wsdl';
$username = 'user';
$password = 'pass';

// include the console and client classes
include "class_console.php";
include "class_client.php";

// create a client resource / connection
$client = new Client($location, $wsdl, $username, $password);

while ($loops <= 100)   
    {
    $dostuff;
    }
?>

class_console.php

<?php
class Console {
// the connection resource
private $connection = NULL;

/**
* When this object is instantiated a connection will be made to the console
*/
public function __construct($location, $wsdl, $username, $password, $proxyHost = NULL, $proxyPort = NULL) {

if(is_null($proxyHost) || is_null($proxyPort)) $connection = new SoapClient($wsdl, array('login' => $username, 'password' => $password));
else $connection = new SoapClient($wsdl, array('login' => $username, 'password' => $password, 'proxy_host' => $proxyHost, 'proxy_port' => $proxyPort));
$connection->__setLocation($location);
$this->connection = $connection;
return $this->connection;
}

/**
* Will print any type of data to screen, where supported by print_r
*
* @param $var - The data to print to screen
* @return $this->connection - The connection resource
**/
public function screen($var) {
print '<pre>';
print_r($var);
print '</pre>';
return $this->connection;
}

/**
* Returns a server / connection resource
*
* @return $this->connection - The connection resource
*/
public function srv() {
return $this->connection;
}

}
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about Xml