我正在运行一个脚本,它会检查域名的可用性(10次)并输出域名(如果有)和时间戳(以毫秒为单位)。
你能找到一些甚至在婚礼上放慢脚本速度的东西吗? 如果你可以请调整和重新发布或建议可以做得更好,这将是非常感谢!谢谢。
<?php
date_default_timezone_set('Australia/Brisbane');
$loops = 0;
function udate($format, $utimestamp = null) {
if (is_null($utimestamp))
$utimestamp = microtime(true);
$timestamp = floor($utimestamp);
$milliseconds = round(($utimestamp - $timestamp) * 1000000);
return date(preg_replace('`(?<!\\\\)u`', $milliseconds, $format), $timestamp);
}
function GetCurlPage ($pageSpec)
{
$ch = curl_init($pageSpec);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$tmp = curl_exec ($ch);
curl_close ($ch);
$tmp = preg_replace('/(?s)<meta http-equiv="Expires"[^>]*>/i', '', $tmp);
$tmp = explode('<br>', $tmp);
foreach ($tmp AS $line) {
//echo '<pre>';
//print_r($line);
//echo '</pre>';
}
// Do something with each line.
echo $tmp[0];
echo "<br>";
echo $tmp[1];
//echo $tmp[2];
echo "<br>";
echo udate('H:i:s:u');
echo "<br><br>";
return $tmp;
}
while ($loops <= 10)
{
$suffixes=urlencode("com.au");
$domain = "sampledomain";
$fuzzysearch = "0";
$returnUrl="http://mydomain.com.au/test.php";
$url = "https://apidomain.com.au/check.php?domain=" .
$domain . "&suffixes=" . $suffixes . "&fuzzysearch=" . $fuzzysearch;
$output = GetCurlPage("$url");
++$loops;
}
?>
答案 0 :(得分:5)
因为你需要对外部网站进行10次卷曲,因此速度很慢
两个建议
我更喜欢建议1
答案 1 :(得分:1)
$suffixes=urlencode("com.au");
中的代码放入循环中的$domain . "&suffixes=" . $suffixes . "&fuzzysearch=" . $fuzzysearch;
foreach ($tmp AS $line) {
循环答案 2 :(得分:0)
按if (is_null($utimestamp))
更改if ($utimestamp === null)
,以防止PHP必须调用函数is_null()
。