我想用Josh Fraser(https://github.com/LionsAd/rolling-curl/blob/master/RollingCurl.php)的RollingCurl脚本加载多个网页。对于每个网页,我将首先在同一会话中发送GET请求,然后发送POST请求。
这是我的代码,该代码可以使我首先为具有两个不同会话的每个网站发送GET请求,然后发送POST请求。
annybody可以告诉我如何在一个会话中发送此邮件吗?
<?php
//Initials
$html_get = [];
$html_post = [];
require("RollingCurl.php");
//Website URLs to array
$urls = array( some website urls... );
//Function: Load Websites with GET and filter datas to arrays
function request_callback_get($response, $info) {
global $html_get;
$html_get[$info["url"]] = $response;
//Search some strings on the Website
$dom = new DOMDocument();
...
}
//Function: Load Websites with POST and filter datas to arrays
function request_callback_post($response, $info) {
global $html_post;
$html_post[$info["url"]] = $response;
}
//Execute GET multi loading Websites ("windows_size" = max. number of parallel connections)
$rc = new RollingCurl("request_callback_get");
$rc->window_size = 20;
foreach ($urls as $url) {
$request = new RollingCurlRequest($url);
$request->options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30,
CURLOPT_COOKIEJAR => 'cookie.txt');
$rc->add($request);
}
$rc->execute();
//Load all required data from GET request
$data = array(
"some data" => $some data from GET request,
"some data" => $some data from GET request,
"some data" => $some data from GET request
);
//Execute POST multi loading Websites ("windows_size" = max. number of parallel connections)
$rc = new RollingCurl("request_callback_post");
$rc->window_size = 20;
foreach ($urls as $url) {
$request = new RollingCurlRequest($url);
$request->post_data = $data;
$request->options = array(
CURLOPT_COOKIEJAR => 'cookie.txt',
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30);
$rc->add($request);
}
$rc->execute();
echo $html_post[$url];
?>