开发者

PHP & SOAP efficieny - help with small code please

I connect up to a domain API and perform an availability check on only one domain.

  • I would like to loop this 10 times, in the most efficient way to check for any changes in status
  • I would like it to do the checks as quickly开发者_运维问答 as possible (reduce the time between checks)
  • I would like it to ouput each time it completes a check (if a multiple loop is in place it only outputs all checks once finished, in one go, rather than one at a time after each check / iteration in the loop)

Cheers!

<?php

// connection credentials and settings
$location = 'https://TheApiServiceURL.com/';
$wsdl = $location.'?wsdl';
$username = 'APIuser';
$password = 'APIpass';

// 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);

/**
* Example usage and output results to screen
*/

// Example #1: Check domain name availability
print('========== consoleMethod[domainLookup] ==========<br/>');
$client-­‐>set('domain', 'domain.com');
$client-­‐>domainLookup();
$client-­‐>screen($client-­‐>response());
$client-­‐>unset('domain');

?>


I googled sub-strings of your code. I found the documentation - the provided code is from the examples section.

About the Class "Client"

This is what it says about the screen method:

public  function screen($var)
{
    print '<pre>';
    print_r($var);
    print '</pre>';
    return $this­‐>connection;
} 

and

public function  response()
{
   return $this-­>response;
}  


Efficiently Looping 10 Times

If you want to get your response every iteration (is what you want, right?), do this:

$client‐>set('domain', 'domain.com');

$i=0;
while($i<10)
    {

        $client‐>domainLookup();
        echo $client‐>response(); 
        // or  $client‐>screen($client‐>response());            

    $i++;
    }

$client-­>unset('domain');


According to this benchmark while beats for. But it will be a minor difference at 10 iterations. However, If you really do want to tweak it I suggest timing different approaches- maybe even trying to copy paste the commands 10 times.


DomainLookup() Speed

Or refered to as "Checking Speed" by you.

This depends on the function domainLookup() which is provided by the api. So you'll have to see what this function is doing if you want to make the "checking speed" quicker. You could multi-thread the function but php isn't really made for that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜