模拟POST1
1. 模拟提交 1function 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 &'); |