admin管理员组文章数量:1123105
php version 5.6 is running on a virtual host, so the sleep and usleep functions are disabled, and I don't have permission to enable them. I have to hang the script for a while before I can continue executing it. So far I've thought of using curl or the fsockopen function to send a request that suspends the script. But I don't know what the harm is, how to accurately control the request time, or if there are such sites that only respond in 1-2 seconds. I thought for a day, did not come up with a good way, please help me, sincerely thank you.
php version 5.6 is running on a virtual host, so the sleep and usleep functions are disabled, and I don't have permission to enable them. I have to hang the script for a while before I can continue executing it. So far I've thought of using curl or the fsockopen function to send a request that suspends the script. But I don't know what the harm is, how to accurately control the request time, or if there are such sites that only respond in 1-2 seconds. I thought for a day, did not come up with a good way, please help me, sincerely thank you.
Share Improve this question asked 4 hours ago seansean 531 silver badge3 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 0Use an webrequest to unknown source
There are several way to use Webrequests for an predigtable Timeout ... So the code below isonly "an Idea" of what to do.
function curlSleep(
$sleepSecs = 5,
$url = 'www.ineverwillreachthis.lostinspace'
) {
$startTime = microtime(true);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $sleepSecs);
try {
$output = curl_exec($ch);
$endTime = microtime(true);
if (curl_errno($ch)) {
echo "cURL error: " . curl_error($ch);
} else {
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($statusCode === 200) {
$duration = $endTime - $startTime;
echo "Response time: " . $duration . " seconds";
} else {
echo "Server response error with status code: " . $statusCode;
}
}
} catch (Throwable $e) {
} finnaly {
curl_close($ch);
}
}
本文标签: curlHow to suspend php threads when sleep and usleep functions are disabledStack Overflow
版权声明:本文标题:curl - How to suspend php threads when sleep and usleep functions are disabled? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736545942a1944446.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
shell_exec('sleep 10');
– Barmar Commented 3 hours agofunction simpleSleep($seconds){$timeEnd = time() + $seconds; while($timeEnd > time()) for ($n = 1; $n < 100000000; $n++);}
, this should work too:function simpleSleep($seconds){$timeEnd = time() + $seconds; while($timeEnd > time());}
– TUPKAP Commented 3 hours agosleep
function which is currently disabled, can you enable it for me?" – Chris Haas Commented 2 hours ago