Download the PHP package initphp/socket without Composer
On this page you can find all versions of the php package initphp/socket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package socket
InitPHP Socket Manager
PHP Socket (TCP, TLS, UDP, SSL) Server/Client Library
Requirements
- PHP 7.4 or higher
- PHP Sockets Extension
Installation
Usage
Supported Types :
- TCP
- UDP
- TLS
- SSL
Factory
\InitPHP\Socket\Socket::class
It allows you to easily create socket server or client.
Socket::server()
$handler
:Socket::SSL
,Socket::TCP
,Socket::TLS
orSocket::UDP
$host
: Identifies the socket host. If not defined or left blank, it will throw an error.$port
: Identifies the socket port. If not defined or left blank, it will throw an error.$argument
: This value is the value that will be sent as 3 parameters to the constructor method of the handler.- SSL or TLS = (float) Defines the timeout period.
- UDP or TCP = (string) Defines the protocol family to be used by the socket. "v4", "v6" or "unix"
Socket::client()
$handler
:Socket::SSL
,Socket::TCP
,Socket::TLS
orSocket::UDP
$host
: Identifies the socket host. If not defined or left blank, it will throw an error.$port
: Identifies the socket port. If not defined or left blank, it will throw an error.$argument
: This value is the value that will be sent as 3 parameters to the constructor method of the handler.- SSL or TLS = (float) Defines the timeout period.
- UDP or TCP = (string) Defines the protocol family to be used by the socket. "v4", "v6" or "unix"
Methods
connection()
: Initiates the socket connection.
disconnect()
: Terminates the connection.
read()
: Reads data from socket.
write()
: Writes data to the socket
Server Methods
live()
:
wait()
:
Special methods for TLS and SSL.
TLS and SSL work similarly.
There are some additional methods you can use from TLS and SSL sockets.
timeout()
: Defines the timeout period of the current.
blocking()
: Sets the blocking mode of the current.
crypto()
: Turns encryption on or off on a connected socket.
Possible values for $method
are;
- "sslv2"
- "sslv3"
- "sslv23"
- "any"
- "tls"
- "tlsv1.0"
- "tlsv1.1"
- "tlsv1.2"
- NULL
option()
: Defines connection options for SSL and TLS. see; https://www.php.net/manual/en/context.ssl.php
Socket Server
Example :
Socket Client
Example :
In the above example, a simple smtp connection to gmail is made.
Credits
License
Copyright © 2022 MIT License
All versions of socket with dependencies
ext-sockets Version *