Answer the question
In order to leave comments, you need to log in
Will php-fpm + ngnix help with our parsing load problem?
People, we can’t figure out where the thin place is and where our parsing algorithm breaks.
There is a third-party site that hosts the results of sports and eSports events. We take the results from him. But not by the crown, because there you can pull a maximum of once a minute, but with the help of a self-written daimon.
The code is something like this
$parser_result = json_decode(file_get_contents($url), true);
foreach ($parser_result['Value'] as $game){
$cdate_unixtime = $game['S'];
$gid = intval($game['I']);
$urls[] = $url."&game_id=".$gid;
}
// array of curl handles
$multiCurl = [];
// data to be returned
$result = [];
// multi handle
$mh = curl_multi_init();
foreach ($urls as $i => $url) {
// URL from which data will be fetched
$multiCurl[$i] = curl_init();
curl_setopt($multiCurl[$i], CURLOPT_URL,$url);
curl_setopt($multiCurl[$i], CURLOPT_HEADER,0);
curl_setopt($multiCurl[$i], CURLOPT_RETURNTRANSFER,1);
curl_multi_add_handle($mh, $multiCurl[$i]);
}
$index=null;
do {
curl_multi_exec($mh,$index);
} while($index > 0);
// get content and remove handles
foreach($multiCurl as $k => $ch) {
$req = curl_multi_getcontent($ch);
$parser_kf = json_decode($req, true);
// здесь мы вычленяем данные, кладем их в базу, а потом ниже удаляем хендлер соединения, весь код я опустил
curl_multi_remove_handle($mh, $ch);
}
// закрываем соединение
curl_multi_close($mh);
#!/bin/bash
while true;
do
/opt/php72/bin/php parser.php;
sleep 5;
done
nohup ./daemon.sh >/dev/null 2>&1 &
Answer the question
In order to leave comments, you need to log in
no it won't solve the problem php-fpm will give you 20% speed but won't solve the problem.
but if you have 5.6, then switching to 7.2 will give you a real 100% speed boost and a real load reduction.
As a reduction option, run them sequentially
nginx has nothing to do with it at all.
It looks like memory is leaking somewhere, without debugging, I can advise you to either cram more unset, or rewrite it so that when the process crashes, it restarts and starts from where it left off (for example, implement a certain queue).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question