Bulk checkDomainRequest

From Openprovider API documentation

Jump to: navigation, search

Before using this script, please make sure to read API General Examples

<?php
require_once('API.php');
$api = new OP_API('https://api.openprovider.eu');

$username = '--';
$password = '--';

if (!preg_match('/^[a-z\d\-]+$/i', $_SERVER['argv'][1])) {
  die("Provide a domain name (ASCII, without extension) and an optional limit. Syntax:\n    check-bulk.php somedomain [limit]\n\n");
}
if (isset($_SERVER['argv'][2]) && !preg_match('/^\d+$/', $_SERVER['argv'][2])) {
  die("Provide a domain name (ASCII, without extension) and an optional limit. Syntax:\n    check-bulk.php somedomain [limit]\n\n");
}

$domain   = $_SERVER['argv'][1]; // domain name without extension
$limit    = $_SERVER['argv'][2] ? $_SERVER['argv'][2] : NULL; // stop processing this script after this number of checks

$request = new OP_Request;
$request->setCommand('searchExtensionRequest')
  ->setAuth(array('username' => $username, 'password' => $password))
  ->setArgs(array(
    'limit' => 3000,
    'status' => 'ACT',
    'onlyNames' => true,
  ));
$reply = $api->process($request);
$res = $reply->getValue();

foreach ($res['results'] as $ext) {
  $request = new OP_Request;
  $request->setCommand('checkDomainRequest')
    ->setAuth(array('username' => $username, 'password' => $password))
    ->setArgs(array(
      'domains' => array(
        array(
          'name' => $domain,
          'extension' => $ext,
        ),
      )
    ));
  $reply = $api->process($request);
  if ($reply->getFaultCode() == 0) {
    $res = $reply->getValue();
    echo $domain.'.'.$ext."\t".$res[0]['status']."\n";
  }
  else {
    echo $domain.'.'.$ext."\t".$reply->getFaultCode().': '.$reply->getFaultString()."\n";
  }
  if ($limit && ++$cnt >= $limit) break;
}

?>
Views
Personal tools