php / doc-en

English PHP documentation
484 stars 724 forks source link

curl_getinfo() may benefit from a table like curl_setopt() #1345

Open henri9813 opened 2 years ago

henri9813 commented 2 years ago

Description

The following code works on:

root@32bf1ba2b92c:/app# php --version
PHP 8.0.8 (cli) (built: Jul 22 2021 02:36:54) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies
root@32bf1ba2b92c:/app# curl
curl         curl-config  
root@32bf1ba2b92c:/app# curl --version
curl 7.64.0 (x86_64-pc-linux-gnu) libcurl/7.64.0 OpenSSL/1.1.1d zlib/1.2.11 libidn2/2.0.5 libpsl/0.20.2 (+libidn2/2.0.5) libssh2/1.8.0 nghttp2/1.36.0 librtmp/2.3
Release-Date: 2019-02-06
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL 
<?php
           $url = "https://google.fr";
            $ch = curl_init($url);

            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 120);
 $response = curl_getinfo($ch);
           echo $response["total_time_us"]

Resulted in this output:

the time in us

On another machine which has:

server :~/htdocs$ php -v
PHP 8.0.14 (cli) (built: Dec 16 2021 03:01:07) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.14, Copyright (c), by Zend Technologies
server :~/htdocs$ curl --version
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.53.1 zlib/1.2.7 libidn/1.28 libssh2/1.8.0
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp 
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets 

i got:

Warning: Undefined array key "total_time_us"  

Why ?

On the php.net documentation ,there is nothing about this total_time_us key.

PHP Version

PHP 8.0.14

Operating System

Centos 7

damianwadley commented 2 years ago

"total_time_us" is CURLINFO_TOTAL_TIME_T and requires cURL 7.61 or later. https://curl.se/libcurl/c/CURLINFO_TOTAL_TIME_T.html

The curl_getinfo page could benefit from a table like curl_setopt.

henri9813 commented 2 years ago

Oh okay,

May this should be define in the php documentation https://www.php.net/manual/en/function.curl-getinfo.php ?

The only solution is to upgrade curl to 7.61 ?

Best regards

damianwadley commented 2 years ago

May this should be define in the php documentation https://www.php.net/manual/en/function.curl-getinfo.php ?

Yes.

The only solution is to upgrade curl to 7.61 ?

If you need total_time_us then yes. Note that curl 7.29 is almost 9 years old and 7.61 is more than 3 years old.

henri9813 commented 2 years ago

Yes of course, but this updates is not included witht CentOS 7.

Thanks,