Skip to content

Commit 4de6a1d

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 4de6a1d

File tree

2 files changed

+45
-0
lines changed

2 files changed

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

ext/curl/tests/skipif-nocaddy.inc

Lines changed: 1 addition & 0 deletions
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)