模擬POST1
1. 模擬提交 1 function cpost($url,$data){ // vd($url,0); // vd($data,0); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 對認證證書來源的檢查 // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); // 從證書中檢查SSL加密算法是否存在 // curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模擬用戶使用的瀏覽器 // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自動跳轉 // curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // 自動設置Referer curl_setopt($ch, CURLOPT_POST, 1); // 發送一個常規的Post請求 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // Post提交的數據包 curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 設置超時限制防止死循環 curl_setopt($ch, CURLOPT_HEADER, 0); // 顯示返回的Header區域內容 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 獲取的信息以文件流的形式返回 curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8'); $tmpInfo = curl_exec($ch); // 執行操作 if (curl_errno($ch)) { $tmpInfo = 'Errno'.curl_error($ch);//捕抓異常 } curl_close($ch); // 關閉CURL會話 return $tmpInfo; }
2. 模擬提交 2
function post2($url,$data){ $context = array( 'http'=>array( 'method'=>'POST', 'header'=>'Content-type: application/x-www-form-urlencoded'."\r\n". 'User-Agent : Jimmy\’s POST Example beta'."\r\n". 'Content-length: '.strlen($data)+8, 'content'=>'mypost='.$data) ); $stream_context = stream_context_create($context); $data = file_get_contents($url,FALSE,$stream_context); return $data; }
3.PHP nohup 的方法
exec('nohup php ../test.php '. base64_encode(json_encode($params)) ); system('nohup ../test2.sh >>/tmp/test2.log &');