forked from PHPExpertsInc/domainsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
135 lines (105 loc) · 3.89 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/env php
<?php
// This file is a part of the Domain Search App, a PHPExperts.pro Project.
//
// Copyright (c) 2012 Theodore R.Smith ([email protected])
// DSA-1024 Fingerprint: 10A0 6372 9092 85A2 BB7F 907B CB8B 654B E33B F1ED
// Provided by the PHP University (www.phpu.cc) and PHPExperts.pro (www.phpexperts.pro)
//
// This file is dually licensed under the terms of the following licenses:
// * Primary License: OSSAL v1.0 - Open Source Software Alliance License
// * Key points:
// 5.Redistributions of source code in any non-textual form (i.e.
// binary or object form, etc.) must not be linked to software that is
// released with a license that requires disclosure of source code
// (ex: the GPL).
// 6.Redistributions of source code must be licensed under more than one
// license and must not have the terms of the OSSAL removed.
// * See LICENSE.ossal for complete details.
//
// * Secondary License: Creative Commons Attribution License v3.0
// * Key Points:
// * You are free:
// * to copy, distribute, display, and perform the work
// * to make non-commercial or commercial use of the work in its original form
// * Under the following conditions:
// * Attribution. You must give the original author credit. You must retain all
// Copyright notices and you must include the sentence, "Based upon work from
// PHPExperts.pro (www.phpexperts.pro).", wherever you list contributors.
// * See LICENSE.cc_by for complete details.
include 'thrive/Autoloader.php';
class MemcacheMock
{
public function get($key) { return null; }
public function set($key, $data, $ttl='') { }
}
$memcache = injectMemcache();
$loader = new Thrive_Autoloader(new fCache('memcache', $memcache));
if (!isset($argv[1]))
{
echo "ERROR: Please provide at least one domain name to search.\n";
exit;
}
$domainList = array();
for ($a = 1; $a < $argc; ++$a)
{
$domainList[] = $argv[$a];
}
function injectMemcache($mode = '')
{
static $memcache;
if ($mode == 'test')
{
return new MemcacheMock;
}
if ($memcache === null)
{
$memcache = new Memcached;
$memcache->addServer('localhost', 11211);
}
return $memcache;
}
// TEST API
/*
$accessCreds = new Model_APIAccessCredentials;
$accessCreds->username = 'hopeseekr';
$accessCreds->apiKey = '33d1f7295601432794736256a342f416';
$accessCreds->ipAddress = '68.233.253.127';
$client = new DomainSearcher(new NameCheapAPI_Sandbox_DomainAvailablility($accessCreds, new Thrive_URL_Downloader, new MemcacheMock));
$memcache = injectMemcache('test');
*/
// Prod API
$accessCreds = new Model_APIAccessCredentials;
$accessCreds->username = 'hopeseekr';
$accessCreds->apiKey = 'c2eccaf232ee4f289f118cd043e07be4';
$accessCreds->ipAddress = '68.233.253.127';
$client = new DomainSearcher(new NameCheapAPI_DomainAvailablility($accessCreds));
//header('Content-Type: text/plain');
//print_r($domainList); exit;
$size = count($domainList);
$startTime = time();
$processed = 0;
// Do 30 max per minute.
$numToSearch = 10;
for ($a = 0; $a < $size && $processed < 30 && time() - $startTime < 60; $a += $numToSearch)
{
$domainsToSearch = array_splice($domainList, 0, $numToSearch);
// - Still search alphabetically.
sort($domainsToSearch);
echo "Querying " . join(', ', $domainsToSearch) . ":\n";
$queriedDomains = $client->checkDomainAvailability($domainsToSearch);
// Update the cache.
// - Realphabetize the domain list.
sort($domainList);
$timeToWait = 20 + $startTime;
if ($timeToWait - time() == 0) { continue; }
echo "Status:\n\n";
$count = 1;
foreach ($queriedDomains as $domain => $status)
{
$status = ($status === true) ? 'Available' : 'Not available';
echo " {$count}. $domain: $status\n";
++$count;
}
$processed += $numToSearch;
}