I did this
In short
If you reuse a CURL handle in PHP the HTTP code (CURLINFO_HTTP_CODE) may come from a previous FTP request.
Long description
I use CURL to download an FTP file in PHP. Later I reuse the handle to download an HTTPS file from a completely different host.
The HTTPS connection successfully downloads the file but the HTTP return code reported by CURL is 221 which comes from the FTP connection of the previous request.
I traced the FTP connection in Wireshark and it looks like this:
226 Transfer completed.
QUIT
221 Goodbye.
So here again what I do and what probably happens behind the scenes:
- I use CURL to download a file from an FTP server. CURLINFO_HTTP_CODE is 226 (everything good).
- CURL will leave the FTP connection open because it may be needed again later (everything good).
- I reuse the CURL handle to download a file from an HTTPS server of a completely different host (everything good).
- CURL receives the HTTP header and after that it downloads let's say 50% of the file (everything good).
- While the HTTP download is running, CURL decides to close the FTP connection of the previous request (everything good).
- The FTP server replies "221 Goodbye." This overwrites the valid HTTP code with an invalid value of a previous request (221) (not good).
- The HTTP download finishes but the CURLINFO_HTTP_CODE (221) is invalid and of a previous FTP request (not good).
I am using PHP 8.2.10-2ubuntu1 and curl_version() reports 8.2.1.
I reported this here because I thought it's probably more a CURL bug than a PHP bug.
I expected the following
At the end I expected CURLINFO_HTTP_CODE to report the HTTP code of the last request.
curl/libcurl version
PHP curl plugin 8.2.1
operating system
KUbuntu 23.10
I did this
In short
If you reuse a CURL handle in PHP the HTTP code (CURLINFO_HTTP_CODE) may come from a previous FTP request.
Long description
I use CURL to download an FTP file in PHP. Later I reuse the handle to download an HTTPS file from a completely different host.
The HTTPS connection successfully downloads the file but the HTTP return code reported by CURL is 221 which comes from the FTP connection of the previous request.
I traced the FTP connection in Wireshark and it looks like this:
So here again what I do and what probably happens behind the scenes:
I am using PHP 8.2.10-2ubuntu1 and curl_version() reports 8.2.1.
I reported this here because I thought it's probably more a CURL bug than a PHP bug.
I expected the following
At the end I expected CURLINFO_HTTP_CODE to report the HTTP code of the last request.
curl/libcurl version
PHP curl plugin 8.2.1
operating system
KUbuntu 23.10