您好,登錄后才能下訂單哦!
<?php function getRequestCookie($webHomePageUrl, $cookieFileName) { //初始化一個curl會話 $curl = curl_init(); $options = array( CURLOPT_URL => $webHomePageUrl, //設置請求的url CURLOPT_HTTPGET => 1, //以get方式請求 CURLOPT_COOKIEJAR => $cookieFileName, //連接結束后保存cookie信息到文件。 CURLOPT_TIMEOUT => 300, //設置CURL允許執行的最長秒數。 CURLOPT_RETURNTRANSFER => true, //將curl_exec()獲取的信息以文件流的形式返回,也就是不直接輸出。 CURLOPT_HEADER => TRUE //啟用時會將頭文件的信息作為數據流輸出。 ); 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 設置curl的傳輸選項 $options = array(CURLOPT_URL => $requestUrl, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $postData, CURLOPT_HEADER => TRUE, //啟用時會將頭文件信息作為數據流輸出 CURLOPT_COOKIEFILE => $cookieFileName, //包含cookie數據的文件名 CURLOPT_RETURNTRANSFER => TRUE, //將curl_exec()獲取的信息以文件流的形式返回,也就是不直接輸出。 ); //為curl傳輸會話批量設置選項 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(); }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。