inexplicably, CPU is particularly responsible. And the Job executed by the following code has been executed for several days, but it is not finished. Why can"t the program end?
this loop is the only one in the entire code, so it should be the unfinished problem of do-while
below. But why can"t it end? I suspect that running
is always greater than 0. Will this happen?
<?php
public function run()
{
$mh = curl_multi_init();
foreach ($this->_serverList as $key => $hostname) {
$url = "http://{$hostname}:8360/MonitorInterfaceJob.php?interval=" . $this->_timeInterval;
$ch[$key] = curl_init($url);
curl_setopt($ch[$key], CURLOPT_HEADER, 0);
curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($mh, $ch[$key]);
}
//
do {
curl_multi_exec($mh, $running);
} while ($running > 0);
foreach ($this->_serverList as $key => $hostname) {
curl_multi_remove_handle($mh, $ch[$key]);
}
curl_multi_close($mh);
}
compare the official reference code:
$active = null;
//
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
made the following inference:
- does not set the expiration time of the request for a single curl. However, php sets the timeout by default. So this should not be done.
- compared with the officially recommended code,
running
is actually used as program judgment logic. It"s just officially recommended code, which is strictly executed according to libcurl . -
curl_multi
make calls viaselect ()
orpoll ()
, I won"t make a distinction. But I understand that this approach is equivalent to a long poll, so the CPU consumption is more objective.
Please help me analyze