Download the PHP package icicleio/socket without Composer

On this page you can find all versions of the php package icicleio/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

Asynchronous Sockets for Icicle

This library is a component for Icicle, providing an asynchronous stream socket server, connector, and datagram. Like other Icicle components, this library uses Generators to make writing asynchronous code more like writing synchronous code.

Build Status Coverage Status Semantic Version @icicleio on Twitter

Requirements
Suggested
Installation

The recommended way to install is with the Composer package manager. (See the Composer installation guide for information on installing and using Composer.)

Run the following command to use this library in your project:

You can also manually edit composer.json to add this library as a project requirement.

The socket component implements network sockets as coroutine-based streams, server, and datagram. Creating a server and accepting connections is very simple, requiring only a few lines of code.

The example below implements a simple HTTP server listening on 127.0.0.1:8080 that responds to any request with the contents of the client request as the body of the response. This example is implemented using coroutines (see the Coroutine API documentation) and the basic sockets provided by this package.

Documentation

Function prototypes

Prototypes for object instance methods are described below using the following syntax:

Server

The Icicle\Socket\Server\BasicServer class implements Icicle\Socket\Server\Server, a coroutine-based interface for creating a TCP server and accepting connections.

BasicServer Constructor

Creates a server from a stream socket server resource generated from stream_socket_server(). Generally it is better to use Icicle\Socket\Server\DefaultServerFactory to create a Icicle\Socket\Server\BasicServer instance.


accept()

A coroutine that is resolved with an object implementing Icicle\Socket\Socket when a connection is accepted.

Resolution Type Description
Fulfilled Icicle\Socket\Socket Accepted client connection.
Rejected Icicle\Socket\Exception\BusyException If the server already had an accept pending.
Rejected Icicle\Socket\Exception\UnavailableException If the server was previously closed.
Rejected Icicle\Socket\Exception\ClosedException If the server is closed during pending accept.

getAddress()

Returns the local IP address as a string.


getPort()

Returns the local port.

ServerFactory

Icicle\Socket\Server\DefaultServerFactory (implements Icicle\Socket\Server\ServerFactory) can be used to create server instances from a IP or unix socket path, port number (null for unix socket), and list of options.

create()

Creates a server bound and listening on the given ip or unix socket path and port number (null for unix socket).

Option Type Description
backlog int Connection backlog size. Note that the operating system variable SOMAXCONN may set an upper limit and may need to be changed to allow a larger backlog size.
pem string Path to PEM file containing certificate and private key to enable SSL on client connections.
passphrase string PEM passphrase if applicable.
name string Name to use as SNI identifier. If not set, name will be guessed based on $host.

Socket

Icicle\Socket\NetworkSocket objects implement Icicle\Socket\Socket and are used as the fulfillment value of the coroutine returned by Icicle\Socket\Server\BasicServer::accept() (see documentation above). (Note that Icicle\Socket\Server\BasicServer can be easily extended and modified to fulfill accept requests with different objects implementing Icicle\Socket\Socket.)

The class extends Icicle\Stream\Pipe\DuplexPipe, so it inherits all the readable and writable stream methods as well as adding those below.

NetworkSocket Constructor

Creates a socket object from the given stream socket resource.


enableCrypto()

Enables encryption on the socket. For Socket objects created from Icicle\Socket\Server\Server::accept(), a PEM file must have been provided when creating the server socket (see Icicle\Socket\Server\ServerFactory). Use the STREAM_CRYPTO_METHOD_*_SERVER constants when enabling crypto on remote clients (e.g., created by Icicle\Socket\Server\Server::accept()) and the STREAM_CRYPTO_METHOD_*_CLIENT constants when enabling crypto on a local client connection (e.g., created by Icicle\Socket\Connector\Connector::connect()).


isCryptoEnabled()

Determines if encryption is enabled on the socket.


unshift()

Determines if encryption is enabled on the socket.


getLocalAddress()

Returns the local IP address as a string.


getLocalPort()

Returns the local port.


getRemoteAddress()

Returns the remote IP address as a string.


getRemotePort()

Returns the remote port.

Connector

The Icicle\Socket\Connector\DefaultConnector class (implements Icicle\Socket\Connector\Connector) asynchronously connects to a remote server, returning a coroutine that is fulfilled with an instance of Icicle\Socket\Socket when the connection is successfully established. Note that the host should be given as an IP address, as DNS lookups performed by PHP are synchronous (blocking). If you wish to use domain names instead of IPs, see Icicle\Dns\Connector\Connector in the DNS component.

connect()

Connects asynchronously to the given IP or unix socket path on the given port number (null for unix socket).

Option Type Description
protocol string The protocol to use, such as tcp, udp, s3, ssh. Defaults to tcp.
timeout float Number of seconds until connection attempt times out. Defaults to 10 seconds.
cn string Host name (common name) used to verify certificate. e.g., *.google.com
allow_self_signed bool Set to true to allow self-signed certificates. Defaults to false.
max_depth int Max levels of certificate authorities the verifier will transverse. Defaults to 10.
cafile string Path to bundle of root certificates to verify against.
Resolution Type Description
Fulfilled Icicle\Socket\Socket Fulfilled once the connection is established.
Rejected Icicle\Socket\Exception\FailureException If the connection attempt fails (such as an invalid host).
Rejected Icicle\Awaitable\Exception\TimeoutException If the connection attempt times out.

Datagram

The Icicle\Socket\Datagram\BasicDatagram class implements Icicle\Socket\Datagram\Datagram, a coroutine-based interface for creating a UDP listener and sender.

BasicDatagram Constructor

Creates a datagram from a stream socket server resource generated from stream_socket_server(). Generally it is better to use Icicle\Socket\Datagram\DefaultDatagramFactory to create a Icicle\Socket\Datagram\BasicDatagram instance.


receive()

A coroutine that is fulfilled with an array when a data is received on the UDP socket (datagram). The array is a 0-indexed array containing the IP address, port, and data received, in that order.

Resolution Type Description
Fulfilled array IP address, port, and data received.
Rejected Icicle\Socket\Exception\BusyException If the server already had an accept pending.
Rejected Icicle\Stream\Exception\UnavailableException If the server was previously closed.

send()

Send the given data to the IP address and port. This coroutine is fulfilled with the amount of data sent once the data has successfully been sent.

Resolution Type Description
Fulfilled int Length of data sent.
Rejected Icicle\Socket\Exception\BusyException If the server already had an accept pending.
Rejected Icicle\Stream\Exception\UnavailableException If the server was previously closed.
Rejected Icicle\Stream\Exception\ClosedException If the server is closed during pending accept.

getAddress()

Returns the local IP address as a string.


getPort()

Returns the local port.

DatagramFactory

Icicle\Socket\Datagram\DefaultDatagramFactory (implements Icicle\Socket\Datagram\DatagramFactory) can be used to create datagram instances from a hostname or unix socket path, port number (null for unix socket), and list of options.

create()

Creates a datagram bound and listening on the given IP and port number. No options are defined in this implementation.

Functions

Socket\connect()

Connects asynchronously to the given host on the given port. Uses the global connector interface that can be set using Icicle\Socket\connector().

Option Type Description
protocol string The protocol to use, such as tcp, udp, s3, ssh. Defaults to tcp.
timeout float Number of seconds until connection attempt times out. Defaults to 10 seconds.
cn string Host name (common name) used to verify certificate. e.g., *.google.com
allow_self_signed bool Set to true to allow self-signed certificates. Defaults to false.
max_depth int Max levels of certificate authorities the verifier will transverse. Defaults to 10.
cafile string Path to bundle of root certificates to verify against.
Resolution Type Description
Fulfilled Icicle\Socket\Socket Fulfilled once the connection is established.
Rejected Icicle\Socket\Exception\FailureException If the connection attempt fails (such as an invalid host).
Rejected Icicle\Awaitable\Exception\TimeoutException If the connection attempt times out.

Socket\connector()

Gets the global connector instance. If a Connector instance is provided, that instance is set as the global connector instance.


All versions of socket with dependencies

PHP Build Version
Package Version
Requires icicleio/icicle Version ^0.9.1
icicleio/stream Version ^0.5.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 icicleio/socket contains the following files

Loading the files please wait ....