本文整理汇总了PHP中MainWP_Utility::lock方法的典型用法代码示例。如果您正苦于以下问题:PHP MainWP_Utility::lock方法的具体用法?PHP MainWP_Utility::lock怎么用?PHP MainWP_Utility::lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MainWP_Utility
的用法示例。
在下文中一共展示了MainWP_Utility::lock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _fetchUrl
static function _fetchUrl(&$website, $url, $postdata, $checkConstraints = false, $pForceFetch = false, $verifyCertificate = null, $http_user = null, $http_pass = null, $sslVersion = 0)
{
//$agent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';
$agent = 'Mozilla/5.0 (compatible; MainWP/' . MainWP_System::$version . '; +http://mainwp.com)';
if (!$pForceFetch) {
//todo: RS:
//check if offline
}
$identifier = null;
if ($checkConstraints) {
$semLock = '103218';
//SNSyncLock
//Lock
$identifier = MainWP_Utility::getLockIdentifier($semLock);
//Check the delays
//In MS
$minimumDelay = get_option('mainwp_minimumDelay') === false ? 200 : get_option('mainwp_minimumDelay');
if ($minimumDelay > 0) {
$minimumDelay = $minimumDelay / 1000;
}
$minimumIPDelay = get_option('mainwp_minimumIPDelay') === false ? 1000 : get_option('mainwp_minimumIPDelay');
if ($minimumIPDelay > 0) {
$minimumIPDelay = $minimumIPDelay / 1000;
}
MainWP_Utility::endSession();
$delay = true;
while ($delay) {
MainWP_Utility::lock($identifier);
if ($minimumDelay > 0) {
//Check last request overall
$lastRequest = MainWP_DB::Instance()->getLastRequestTimestamp();
if ($lastRequest > microtime(true) - $minimumDelay) {
//Delay!
MainWP_Utility::release($identifier);
usleep(($minimumDelay - (microtime(true) - $lastRequest)) * 1000 * 1000);
continue;
}
}
if ($minimumIPDelay > 0 && $website != null) {
//Get ip of this site url
$ip = MainWP_DB::Instance()->getWPIp($website->id);
if ($ip != null && $ip != '') {
//Check last request for this site
$lastRequest = MainWP_DB::Instance()->getLastRequestTimestamp($ip);
//Check last request for this subnet?
if ($lastRequest > microtime(true) - $minimumIPDelay) {
//Delay!
MainWP_Utility::release($identifier);
usleep(($minimumIPDelay - (microtime(true) - $lastRequest)) * 1000 * 1000);
continue;
}
}
}
$delay = false;
}
//Check the simultaneous requests
$maximumRequests = get_option('mainwp_maximumRequests') === false ? 4 : get_option('mainwp_maximumRequests');
$maximumIPRequests = get_option('mainwp_maximumIPRequests') === false ? 1 : get_option('mainwp_maximumIPRequests');
$first = true;
$delay = true;
while ($delay) {
if (!$first) {
MainWP_Utility::lock($identifier);
} else {
$first = false;
}
//Clean old open requests (may have timed out or something..)
MainWP_DB::Instance()->closeOpenRequests();
if ($maximumRequests > 0) {
$nrOfOpenRequests = MainWP_DB::Instance()->getNrOfOpenRequests();
if ($nrOfOpenRequests >= $maximumRequests) {
//Delay!
MainWP_Utility::release($identifier);
//Wait 200ms
usleep(200000);
continue;
}
}
if ($maximumIPRequests > 0 && $website != null) {
//Get ip of this site url
$ip = MainWP_DB::Instance()->getWPIp($website->id);
if ($ip != null && $ip != '') {
$nrOfOpenRequests = MainWP_DB::Instance()->getNrOfOpenRequests($ip);
if ($nrOfOpenRequests >= $maximumIPRequests) {
//Delay!
MainWP_Utility::release($identifier);
//Wait 200ms
usleep(200000);
continue;
}
}
}
$delay = false;
}
}
if ($website != null) {
//Log the start of this request!
MainWP_DB::Instance()->insertOrUpdateRequestLog($website->id, null, microtime(true), null);
}
if ($identifier != null) {
//.........这里部分代码省略.........