[php-src] Issue #12450: curl send request twice
| From: | dmitryvakulenko | Date: | Mon, 16 Oct 2023 12:58:17 +0000 |
| Subject: | [php-src] Issue #12450: curl send request twice | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245586@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12450
Author: dmitryvakulenko
### Description
When curl send two requests and second one closing by timeout, curl reconnect and send it one more
times. This happend only if CURLOPT_CUSTOMREQUEST was used.
Client code:
```php
<?php
declare(strict_types=1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_URL, "http://localhost");
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, "http://localhost");
curl_exec($ch);
curl_close($ch);
```
Server code written on Go 1.21:
```go
package main
import (
"log"
"net/http"
"time"
)
type Handler struct {
amount int
}
func (p *Handler) ServeHTTP(respw http.ResponseWriter, req *http.Request) {
log.Printf("Got %s request %v from %s\n", req.Method, req.URL.String(), req.RemoteAddr)
p.amount += 1
if p.amount == 2 {
time.Sleep(time.Second * 5)
}
return
}
func main() {
h := Handler{}
srv := http.Server{
Addr: ":80",
Handler: &h,
ReadTimeout: 2 * time.Second,
WriteTimeout: 2 * time.Second,
}
srv.ListenAndServe()
}
```
Resulted in this output:
```
2023/10/16 14:04:19 Got POST request / from 172.18.0.12:35374
2023/10/16 14:04:19 Got POST request / from 172.18.0.12:35374
2023/10/16 14:04:24 Got POST request / from 172.18.0.12:47144
```
But I expected this output instead:
```
2023/10/16 14:04:19 Got POST request / from 172.18.0.12:35374
2023/10/16 14:04:19 Got POST request / from 172.18.0.12:35374
```
### PHP Version
php 7.4-8.1
### Operating System
Ubuntu 20.04, Alpine 3.11.3