dakata__92
Super Moderator
Използвате ли код за изпращане на мулти заявки? Какъв код бихте използвали по темата?
Follow along with the video below to see how to install our site as a web app on your home screen.
Бележка: This feature may not be available in some browsers.
Имах предвид curl_multi_init, като говоря за обработване на множество заявки пратени към сървър едновременно.eLite каза:Какво ще рече "мулти заявки"?
eLite каза:Тука ме хвана неподготвен. :?
Такива задачи обикновено изпълявам на заден план и някакво MQ.
Виж дали това ще ти помогне: https://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/
public function getMultiResponse(Array $urlArray, $threadWidth = Null)
{
$threads = 0;
$running = 0;
$response = array();
if ($threadWidth == null) {
$threadWidth = count($urlArray);
}
$curlMultiExec = function ($threads,$threadWidth,$running,$response)
{
while (curl_multi_exec($this->mch, $running) == CURLM_CALL_MULTI_PERFORM);
curl_multi_select($this->mch);
while ($done = curl_multi_info_read($this->mch)) {
foreach ($response as &$res) {
if ($res['handle'] == $done['handle']) {
$res['response'] = curl_multi_getcontent($done['handle']);
}
}
curl_multi_remove_handle($this->mch, $done['handle']);
curl_close($done['handle']);
$threads--;
}
return array($threads,$threadWidth,$running,$response);
};
foreach ($urlArray as $url => $responseArray) {
switch (true) {
case is_numeric($url) :
$url = $responseArray;
break;
case is_array($responseArray) :
$this->setResponseArray($responseArray);
break;
}
$options = array(
CURLOPT_URL => $url,
CURLOPT_USERAGENT => $this->responseArray["useragent"],
CURLOPT_REFERER => $this->responseArray["referer"],
CURLOPT_ENCODING => $this->responseArray["encoding"],
CURLOPT_HTTPPROXYTUNNEL => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false
);
$ch = curl_init();
curl_setopt_array($ch, $options);
curl_multi_add_handle($this->mch, $ch); //push URL for single rec send into curl stack
$response[] = array("url" => $url, "handle" => $ch);
$threads++;
if ($threads >= $threadWidth) {
// print '<br>'.$threads.'-'.$running;
list($threads,$threadWidth,$running,$response) = $curlMultiExec($threads,$threadWidth,$running,$response);
}
}
while ($threads > 0) {
list($threads,$threadWidth,$running,$response) = $curlMultiExec($threads,$threadWidth,$running,$response);
// print '<br>'.$threads.'-'.$running;
// $threads--;
}
$this->multiCurlOpt = $options;
return $response;
}
В смисъл? Дай пример за какво става на въпрос.lam3r4370 каза:/off Използвай node или go![]()
Тия неща дето ги правиш не се правят на РНР.dakata__92 каза:В смисъл? Дай пример за какво става на въпрос.lam3r4370 каза:/off Използвай node или go![]()
heytar каза:Тия неща дето ги правиш не се правят на РНР.dakata__92 каза:В смисъл? Дай пример за какво става на въпрос.lam3r4370 каза:/off Използвай node или go![]()
C (под производни по име имах предвид) C++, C# а относно Java пак казвам не са ми сила тези езици, че да драскам на тях сложна система.pix3l каза:Не C... Java или C#.
Че той Java като синтаксис е по-беден от PHP...dakata__92 каза:C (под производни по име имах предвид) C++, C# а относно Java пак казвам не са ми сила тези езици, че да драскам на тях сложна система.pix3l каза:Не C... Java или C#.
pthreads is an object-orientated API that provides all of the tools needed for multi-threading in PHP. PHP applications can create, read, write, execute and synchronize with Threads, Workers and Threaded objects.
public function getMultiResponse(Array $urlArray, $threadWidth = Null)
{
$threads = 0;
$running = 0;
$response = array();
if ($threadWidth == null) {
$threadWidth = count($urlArray);
}
$curlMultiExec = function ($threads,$threadWidth,$running,$response)
{
while (curl_multi_exec($this->mch, $running) == CURLM_CALL_MULTI_PERFORM);
curl_multi_select($this->mch);
while ($done = curl_multi_info_read($this->mch)) {
foreach ($response as &$res) {
if ($res['handle'] == $done['handle']) {
$res['response'] = curl_multi_getcontent($done['handle']);
}
}
curl_multi_remove_handle($this->mch, $done['handle']);
curl_close($done['handle']);
$threads--;
}
return array($threads,$threadWidth,$running,$response);
};
foreach ($urlArray as $url => $responseArray) {
switch (true) {
case is_numeric($url) :
$url = $responseArray;
break;
case is_array($responseArray) :
$this->setResponseArray($responseArray);
break;
}
$options = array(
CURLOPT_URL => $url,
CURLOPT_USERAGENT => $this->responseArray["useragent"],
CURLOPT_REFERER => $this->responseArray["referer"],
CURLOPT_ENCODING => $this->responseArray["encoding"],
CURLOPT_HTTPPROXYTUNNEL => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false
);
$ch = curl_init();
curl_setopt_array($ch, $options);
curl_multi_add_handle($this->mch, $ch); //push URL for single rec send into curl stack
$response[] = array("url" => $url, "handle" => $ch);
$threads++;
if ($threads >= $threadWidth) {
// print '<br>'.$threads.'-'.$running;
list($threads,$threadWidth,$running,$response) = $curlMultiExec($threads,$threadWidth,$running,$response);
}
}
while ($threads > 0) {
list($threads,$threadWidth,$running,$response) = $curlMultiExec($threads,$threadWidth,$running,$response);
// print '<br>'.$threads.'-'.$running;
// $threads--;
}
$this->multiCurlOpt = $options;
return $response;
}
По-скоро е поради пренатоварване. Голям масив го подаваш, чрез стъпков цикъл на системата и делиш ресурсите, като използваш по-малко памет и не крашва системата връщайки отговора.vinsbg каза:възможно е да е има outbound лимитация на сървъра и тотал конекции