Skip to content

Commit 025efee

Browse files
committed
test: persistent curl share handles
I opted to use the existing Caddy testing infrastructure since it supports keepalives, whereas it seems the PHP development server does not. Alternatively I could write just enough of a socket listener to confirm that there is only ever a single connection coming from curl, but I believe it is safe to rely on connect_time being zero when a connection is reused.
1 parent e52ca6e commit 025efee

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Basic curl_share test
3+
--EXTENSIONS--
4+
curl
5+
--FILE--
6+
<?php
7+
include 'skipif-nocaddy.inc';
8+
9+
function get_persistent_share_handle(): CurlShareHandle {
10+
return curl_share_init(
11+
[
12+
CURL_LOCK_DATA_CONNECT,
13+
],
14+
"persistent-test",
15+
);
16+
}
17+
18+
$sh1 = get_persistent_share_handle();
19+
$ch1 = curl_init("https://localhost");
20+
21+
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
22+
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
23+
curl_setopt($ch1, CURLOPT_SHARE, $sh1);
24+
25+
$sh2 = get_persistent_share_handle();
26+
$ch2 = curl_init("https://localhost");
27+
28+
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
29+
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
30+
curl_setopt($ch2, CURLOPT_SHARE, $sh2);
31+
32+
var_dump(curl_exec($ch1));
33+
var_dump(curl_exec($ch2));
34+
35+
var_dump("second connect_time: " . (curl_getinfo($ch2)["connect_time"]));
36+
37+
?>
38+
--EXPECT--
39+
string(23) "Caddy is up and running"
40+
string(23) "Caddy is up and running"
41+
string(22) "second connect_time: 0"

ext/curl/tests/skipif-nocaddy.inc

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
$ch = curl_init("https://localhost");
44
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
5+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
56

67
$body = curl_exec($ch);
78

0 commit comments

Comments
 (0)