Я хотел бы загрузить несколько веб-страниц с помощью скрипта RollingCurl от Джоша Фрейзера (https://github.com/LionsAd/rolling-curl/blob/master/RollingCurl.php). Для каждой веб-страницы я отправлю сначала запрос GET, а затем запрос POST в одном сеансе.
Вот мой код, как я могу отправить сначала запрос GET, а затем запрос POST для каждого веб-сайта с двумя различными сеансами.
Может ли кто-нибудь сказать мне, как я могу отправить это за один сеанс?
<?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];
?>