當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WebRequest::start方法代碼示例

本文整理匯總了PHP中WebRequest::start方法的典型用法代碼示例。如果您正苦於以下問題:PHP WebRequest::start方法的具體用法?PHP WebRequest::start怎麽用?PHP WebRequest::start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WebRequest的用法示例。


在下文中一共展示了WebRequest::start方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

    }
    public function run()
    {
        if ($url = $this->url) {
            /*
             * If a large amount of data is being requested, you might want to
             * fsockopen and read using usleep in between reads
             */
            $this->data = file_get_contents($url);
        } else {
            printf("Thread #%lu was not provided a URL\n", $this->getThreadId());
        }
    }
}
$t = microtime(true);
$g = new WebRequest(sprintf("http://www.google.com/?q=%s", rand() * 10));
/* starting synchronized */
if ($g->start()) {
    printf("Request took %f seconds to start ", microtime(true) - $t);
    while ($g->isRunning()) {
        echo ".";
        $g->synchronized(function () use($g) {
            $g->wait(100);
        });
    }
    if ($g->join()) {
        printf(" and %f seconds to finish receiving %d bytes\n", microtime(true) - $t, strlen($g->data));
    } else {
        printf(" and %f seconds to finish, request failed\n", microtime(true) - $t);
    }
}
開發者ID:marcosrachid,項目名稱:pthreads,代碼行數:31,代碼來源:SimpleWebRequest.php


注:本文中的WebRequest::start方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。