| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2019-12-21 16:19 UTC] christian at klemmer dot io
 Description:
------------
When posting a curlFile with curl, I get different results with the same code (and curlFile) if I run it with PHP 7.3 or PHP 7.4.
"Content-Length" is missing and instead replaced by "Transfer-Encoding: chunked". I query an API which is behind an haproxy server. Missing content-lenght seems to remove all files posted on their side.
Nevertheless I would've expected the same behaviour with PHP 7.4 running with the same curl-version.
I'm using the deb.sury.org repository on a debian 10.2 server.
dpkg -l | grep curl
ii  curl                                 7.64.0-4
ii  libcurl3-gnutls:amd64                7.64.0-4
ii  libcurl4:amd64                       7.64.0-4
ii  php7.3-curl                          7.3.13-1+0~20191218.50+debian10~1.gbp23c2da
ii  php7.4-curl                          7.4.1-1+0~20191218.8+debian10~1.gbp21c50e
ii  python3-pycurl                       7.43.0.2-0.1
curl-information out of phpinfo (7.3 testenv and 7.4 testenv are exactly the same):
cURL support	enabled
cURL Information	7.64.0
Age	4
Features:
AsynchDNS	Yes
CharConv	No
Debug	No
GSS-Negotiate	No
IDN	Yes
IPv6	Yes
krb4	No
Largefile	Yes
libz	Yes
NTLM	Yes
NTLMWB	Yes
SPNEGO	Yes
SSL	Yes
SSPI	No
TLS-SRP	Yes
HTTP2	Yes
GSSAPI	Yes
KERBEROS5	Yes
UNIX_SOCKETS	Yes
PSL	Yes
HTTPS_PROXY	Yes
MULTI_SSL	No
BROTLI	No
Protocols	dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtmp, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host	x86_64-pc-linux-gnu
SSL Version	OpenSSL/1.1.1d
ZLib Version	1.2.11
libSSH Version	libssh2/1.8.0
Test script:
---------------
$filename = 'testfile.txt';
if(file_exists($filename) && is_file($filename) && (int)filesize($filename) > 0) {
    try {
        $ch = curl_init('https://example.com/') or die('API down');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLINFO_HEADER_OUT, true);
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, array('test' => new CurlFile($filename)));
        curl_exec($ch);
        $curlInfo = curl_getinfo($ch);
        echo '<pre>'; print_r($curlInfo["request_header"]); echo '</pre>';
        curl_close($ch);
    } catch(Exception $e) {
        echo $e->getMessage();
    }
}
Expected result:
----------------
With PHP 7.3.13:
POST / HTTP/2
Host: example.com
Accept: */*
Content-Length: 245
Content-Type: multipart/form-data; boundary=------------------------c129897ae3ed733b
Actual result:
--------------
With PHP 7.4.1:
POST / HTTP/2
Host: example.com
Accept: */*
Transfer-Encoding: chunked
Content-Type: multipart/form-data; boundary=------------------------ef5ab6d1e2455a47
PatchesPull Requests
Pull requests: 
HistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 02:00:01 2025 UTC | 
For me, using current PHP-7.4 the test script outputs: Linux, curl 7.64.0: POST / HTTP/2 Host: example.com Accept: */* Transfer-Encoding: chunked Content-Type: multipart/form-data; boundary=------------------------df0efab1e65ad7e7 Linux, curl 7.68.0: POST / HTTP/2 Host: example.com accept: */* content-type: multipart/form-data; boundary=------------------------f55b79edfe19cb82 Windows, curl 7.67.0 POST / HTTP/2 Host: example.com accept: */* content-type: multipart/form-data; boundary=------------------------1e758282c5b98dfb So obviously a bug in libcurl which has been fixed in the meantime.