array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.curl_upkeep.php', 1 => 'curl_upkeep', ), 'up' => array ( 0 => 'ref.curl.php', 1 => 'cURL 函数', ), 'prev' => array ( 0 => 'function.curl-unescape.php', 1 => 'curl_unescape', ), 'next' => array ( 0 => 'function.curl-version.php', 1 => 'curl_version', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/curl/functions/curl-upkeep.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 8 >= 8.2.0)
curl_upkeep — Performs any connection upkeep checks
Available if built against libcurl >= 7.62.0.
Some protocols have "connection upkeep" mechanisms. These mechanisms usually send some traffic on existing connections in order to keep them alive; this can prevent connections from being closed due to overzealous firewalls, for example.
Connection upkeep is currently available only for HTTP/2 connections. A small amount of traffic is usually sent to keep a connection alive. HTTP/2 maintains its connection by sending a HTTP/2 PING frame.
示例 #1 curl_upkeep() example
<?php
$url = "https://example.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_UPKEEP_INTERVAL_MS, 200);
if (curl_exec($ch)) {
usleep(300);
var_dump(curl_upkeep($ch));
}
curl_close($ch);
?>