Commit version 24.12.13800

This commit is contained in:
2025-01-06 17:35:06 -05:00
parent b7f6a79c2c
commit 55d9218816
6133 changed files with 4239740 additions and 1374287 deletions

View File

@ -63,46 +63,57 @@ class SocketClient
*/
protected $address;
/**
* Options used to create a stream context
* @see http://php.net/manual/en/function.stream-context-create.php
*
* @var array
*/
protected $options;
/**
* Constructor takes address as argument.
*
* @param string $address
*/
public function __construct($address)
public function __construct($address, $options = null)
{
$this->address = $address;
$this->options = $options;
}
/**
* Connect.
*
* @param integer $timeout Timeout for connection
* @param integer $timeout Timeout for connection
* @param boolean $persistent Persitent connection
* @return void
*/
public function connect($timeout = 30, $persistent = false)
{
$flags = STREAM_CLIENT_CONNECT;
if (true === $persistent) {
$flags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
} else {
$flags = STREAM_CLIENT_CONNECT;
$flags |= STREAM_CLIENT_PERSISTENT;
}
// call stream_socket_client with custom error handler enabled
$handler = new ErrorHandler(
function ($address, $timeout, $flags) {
$options = [
'ssl' => [
'allow_self_signed' => true,
'verify_peer_name' => false,
],
];
$context = stream_context_create($options);
return stream_socket_client($address, $errno, $errstr, $timeout, $flags, $context);
function ($address, $timeout, $flags, array $options = null) {
$errno = null;
$errstr = null;
if (!empty($options)) {
$context = stream_context_create($options);
return stream_socket_client($address, $errno, $errstr, $timeout, $flags, $context);
}
return stream_socket_client($address, $errno, $errstr, $timeout, $flags);
},
$this->address,
$timeout,
$flags
$flags,
$this->options
);
$resource = $handler->execute(__FILE__, __LINE__);
@ -113,9 +124,9 @@ class SocketClient
/**
* Reconnect and optionally use different address.
*
* @param string $address
* @param string $address
* @param integer $timeout
* @param bool $persistent
* @param bool $persistent
*/
public function reconnect($address = null, $timeout = 30, $persistent = false)
{
@ -146,7 +157,7 @@ class SocketClient
*/
public function setBlocking($flag = true)
{
stream_set_blocking($this->resource, (int) $flag);
stream_set_blocking($this->resource, (int)$flag);
return $this;
}
@ -164,7 +175,7 @@ class SocketClient
/**
* Write to stream.
*
* @param string $string String
* @param string $string String
* @param integer $length Limit
* @return void
*/
@ -180,7 +191,7 @@ class SocketClient
/**
* Enable/disable cryptography on stream.
*
* @param boolean $enable Flag
* @param boolean $enable Flag
* @param integer $cryptoType One of the STREAM_CRYPTO_METHOD_* constants.
* @return void
* @throws InvalidArgumentException