您好,登錄后才能下訂單哦!
<?php function getRequestCookie($webHomePageUrl, $cookieFileName) { //初始化一個curl會話 $curl = curl_init(); $options = array( CURLOPT_URL => $webHomePageUrl, //設(shè)置請求的url CURLOPT_HTTPGET => 1, //以get方式請求 CURLOPT_COOKIEJAR => $cookieFileName, //連接結(jié)束后保存cookie信息到文件。 CURLOPT_TIMEOUT => 300, //設(shè)置CURL允許執(zhí)行的最長秒數(shù)。 CURLOPT_RETURNTRANSFER => true, //將curl_exec()獲取的信息以文件流的形式返回,也就是不直接輸出。 CURLOPT_HEADER => TRUE //啟用時會將頭文件的信息作為數(shù)據(jù)流輸出。 ); curl_setopt_array($curl, $options); $result = curl_exec($curl); if ($result === false) { echo 'Curl error:' . curl_errno($curl); } curl_close($curl); return $result; } $webHomePageUrl = 'http://www.oldwebadmin.com'; $cookieFileName = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cookie.log'; getRequestCookie($webHomePageUrl, $cookieFileName); function simulatePOSTRequest($requestUrl, $userAgent, $postData, $cookieFileName) { //初始化一個curl會話 $curl = curl_init(); //curl_setopt 設(shè)置curl的傳輸選項 $options = array(CURLOPT_URL => $requestUrl, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $postData, CURLOPT_HEADER => TRUE, //啟用時會將頭文件信息作為數(shù)據(jù)流輸出 CURLOPT_COOKIEFILE => $cookieFileName, //包含cookie數(shù)據(jù)的文件名 CURLOPT_RETURNTRANSFER => TRUE, //將curl_exec()獲取的信息以文件流的形式返回,也就是不直接輸出。 ); //為curl傳輸會話批量設(shè)置選項 curl_setopt_array($curl, $options); $result = curl_exec($curl); if ($result === false) { echo 'Curl error:' . curl_errno($curl); } curl_close($curl); return $result; } $loginUrl = 'http://www.oldwebadmin.com/login'; $userAgentInfo = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0'; $postData = array('username' => 'username', 'password' => 'password'); $doLoginInfo = simulatePOSTRequest($loginUrl, $userAgentInfo, $postData, $cookieFileName); class myThread extends Thread { private $opInfoFile; public function __construct($fileNames) { $parentDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'thtest' . DIRECTORY_SEPARATOR; $this->opInfoFile = $parentDir . $fileNames; } public function run() { $userAgentInfo = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0'; $cookieFileName = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'cookie.log'; usleep(10); $oprate = 'http://www.oldwebadmin.com/op'; $opostData = array('data1' => 'test1', 'data2' => 'test1', 'data3' => 'test2'); $opInfo = simulatePOSTRequest($oprate, $userAgentInfo, $opostData, $cookieFileName); file_put_contents($this->opInfoFile, serialize($opInfo)); } } $threadPool = array(); for ($i = 0; $i < 100; $i++) { $threadPool[$i] = new myThread('thtest'.$i.'.log'); $threadPool[$i]->start(); }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。