Download the PHP package amphp/socket without Composer

On this page you can find all versions of the php package amphp/socket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package socket

amphp/socket

AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind. amphp/socket is a library for establishing and encrypting non-blocking sockets. It provides a socket abstraction for clients and servers. It abstracts the really low levels of non-blocking streams in PHP.

Latest Release MIT License

Installation

This package can be installed as a Composer dependency.

Requirements

amphp/socket heavily relies on amphp/byte-stream, specifically its ReadableStream and WritableStream interfaces.

Connecting to a Server

amphp/socket allows clients to connect to servers via TCP, UDP, or Unix domain sockets. You can establish a socket connection using Amp\Socket\connect(). It will automatically resolve DNS names and retries other IPs if a connection fails and multiple IPs are available.

Encrypted Connections / TLS

If you want to connect via TLS, use Amp\Socket\connectTls() instead or call $socket->setupTls() on the returned socket.

Handling Connections

Socket implements ReadableStream and WritableStream, so everything from amphp/byte-stream applies for receiving and sending data.

Server

amphp/socket allows listening for incoming TCP connections as well as connections via Unix domain sockets. It defaults to secure TLS settings if you decide to enable TLS.

Listening and Accepting Connections

Use Amp\Socket\Socket\listen() to listen on a port or unix domain socket. It's a wrapper around stream_socket_server that gives useful error message on failures via exceptions.

Once you're listening, accept clients using Server::accept(). It returns a Socket that returns once a new client has been accepted. It's usually called within a while loop:

Handling Connections

Socket implements ReadableStream and WritableStream, so everything from amphp/byte-stream applies for receiving and sending data. It's best to handle clients in their own coroutine, while letting the server accept all clients as soon as there are new clients.

Closing Connections

Once you're done with a client, close the connection using Socket::close(). If you want to wait for all data to be successfully written before closing the connection, use Socket::end(). See above for an example.

Server Address

Sometimes you don't know the address the server is listening on, e.g. because you listed to tcp://127.0.0.1:0, which assigns a random free port. You can use Server::getAddress() to get the address the server is bound to.

Server Shutdown

Once you're done with the server socket, close the socket. That means, the server won't listen on the specified location anymore. Use Server::close() to close the server socket.

Encrypted Connections / TLS

As already mentioned in the documentation for Amp\Socket\Socket\listen(), you need to enable TLS manually after accepting connections. For a TLS server socket, you listen on the tcp:// protocol on a specified address. After accepting clients, call $socket->setupTls() where $socket is the socket returned from SocketServer::accept().

Warning Any data transmitted before Socket::setupTls() completes will be transmitted in clear text. Don't attempt to read from the socket or write to it manually. Doing so will read the raw TLS handshake data that's supposed to be read by OpenSSL.

Self-Signed Certificates

There's no option to allow self-signed certificates in ClientTlsContext since it is no more secure than disabling peer verification. To safely use a self-signed certificate, disable peer verification and require fingerprint verification of the certificate using ClientTlsContext::withPeerFingerprint().

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see LICENSE for more information.


All versions of socket with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
ext-openssl Version *
amphp/amp Version ^2
amphp/dns Version ^1 || ^0.9
amphp/byte-stream Version ^1.6
kelunik/certificate Version ^1.1
league/uri-parser Version ^1.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package amphp/socket contains the following files

Loading the files please wait ....