transport-Eigenschaft
Anforderung (workerman >= 3.3.4)
Setzen Sie die Übertragungseigenschaft, mögliche Werte sind tcp und ssl, standardmäßig ist tcp.
Wenn transport auf ssl gesetzt wird, muss PHP die openssl-Erweiterung installiert haben.
Wenn Workerman als Client eine ssl-verschlüsselte Verbindung zum Server initiiert (https-Verbindung, wss-Verbindung usw.), setzen Sie diese Option auf ssl, wie im folgenden Beispiel gezeigt.
Beispiel (https-Verbindung)
use Workerman\Worker;
use Workerman\Connection\AsyncTcpConnection;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
$task = new Worker();
// Asynchron ein Verbindungsobjekt zu www.baidu.com beim Start des Prozesses erstellen und Daten senden, um Daten zu erhalten
$task->onWorkerStart = function($task)
{
$connection_to_baidu = new AsyncTcpConnection('tcp://www.baidu.com:443');
// Als ssl-verschlüsselte Verbindung festlegen
$connection_to_baidu->transport = 'ssl';
$connection_to_baidu->onConnect = function(AsyncTcpConnection $connection_to_baidu)
{
echo "Verbindung erfolgreich\n";
$connection_to_baidu->send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: keep-alive\r\n\r\n");
};
$connection_to_baidu->onMessage = function(AsyncTcpConnection $connection_to_baidu, $http_buffer)
{
echo $http_buffer;
};
$connection_to_baidu->onClose = function(AsyncTcpConnection $connection_to_baidu)
{
echo "Verbindung geschlossen\n";
};
$connection_to_baidu->onError = function(AsyncTcpConnection $connection_to_baidu, $code, $msg)
{
echo "Fehlercode:$code msg:$msg\n";
};
$connection_to_baidu->connect();
};
// Worker ausführen
Worker::runAll();