Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91dc074

Browse files
committed
update: 默认允许 curl 连接复用
1 parent d1aa92d commit 91dc074

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/SocketClient.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class SocketClient
3636
protected string $e2eEncryptionKey = '';
3737
protected string $paramsMethod = 'path';
3838
protected ?string $loggerFile = null;
39+
protected bool $curlForbidReuse = false; // 是否禁用 curl 复用
3940

4041
public function __construct(string $protocol, string $host, int $port, string $path)
4142
{
@@ -68,6 +69,11 @@ public static function fromUri(string $uri): self
6869
);
6970
}
7071

72+
public function setCurlForbidReuse(bool $curlForbidReuse): void
73+
{
74+
$this->curlForbidReuse = $curlForbidReuse;
75+
}
76+
7177
public function setLogFilePath(string $filepath)
7278
{
7379
if (empty($filepath)) {
@@ -178,6 +184,7 @@ public function send(string $message, string $clientId)
178184
curl_setopt($ch, CURLOPT_POST, true);
179185
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
180186
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
187+
curl_setopt($ch, CURLOPT_FORBID_REUSE, $this->curlForbidReuse);
181188

182189
$headersArr = [];
183190
foreach ($headers as $key => $value) {

think/SocketV2.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class SocketV2 implements LogHandlerInterface
4141
'e2e_encryption_key' => '',
4242
// 发送异常日志(必须确保目录可写)
4343
'socket_error_log' => null,
44+
// 是否禁用 curl 复用
45+
'curl_forbid_reuse' => false,
4446
];
4547

4648
protected array $css = [
@@ -76,6 +78,7 @@ public function __construct(App $app, array $config = [])
7678
$this->client->setE2eEncryptionKey($this->config['e2e_encryption_key'] ?? '', $this->config['e2e_id'] ?? null);
7779
$this->client->setParamsMethod($this->config['client_id_send_method'] ?? 'path');
7880
$this->client->setLogFilePath($this->config['socket_error_log'] ?? null);
81+
$this->client->setCurlForbidReuse($this->config['curl_forbid_reuse'] ?? false);
7982
}
8083

8184
public function save(array $log = []): bool

0 commit comments

Comments
 (0)