osushi/simple-socket

此库可以简单地创建套接字客户端。它使用 PHP 的原生套接字函数编写。

0.0.1 2017-10-13 07:30 UTC

This package is auto-updated.

Last update: 2024-09-29 05:01:30 UTC


README

Packagist

函数

  • 简单创建套接字客户端(目前仅支持 TCP)
  • 在连接后能够写入简单的逻辑

要求

  • PHP >= 7.0.*

用法

composer require osushi/simple-socket

示例

见: https://github.com/Osushi/SimpleSocket/blob/master/sample/Connector.php

$connector = new \SimpleSocket\Connector();
$connector->connectTcp('google.com', 80)->then(function ($conn) {
  $conn->write("GET / HTTP/1.1\r\n\Host: google.com\r\n\r\n");
  
  var_dump($conn->read());
  /*
  string(519) "HTTP/1.1 302 Found
  ....
  </BODY></HTML>"
  */
  
  $conn->close();
});