Download the PHP package cydrickn/socketio without Composer

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

PHP SocketIO Server

PHP Websocket Server that is compatible with socket.io

So far the function use in this package is almost same with the naming in socket.io

Installation

Then in your main php code add

Usage

Initializing your server

To initialize

Server Options

Key Details Default
host The host of the server 127.0.0.1
port The port of the server 8000
mode The mode for server 2 / SWOOLE_PROCESS
sock_type The socket type for server 1 / SWOOLE_SOCK_TCP
settings The setting is base on swoole configuration [] / Empty Array

Server Instance

This is the server \Cydrickn\SocketIO\Socket

Events

Basic Emit

To emit, just need to call the \Cydrickn\SocketIO\Socket::emit

You can also pass as many as you want for the parameters

There is no need to run json_encode on objects/arrays as it will be done for you.

Broadcasting

Broadcast is like just the simple emit, but it will send to all connected client except the current client

Sending to all clients

The toAll will emit a message to all connected clients including the current client

Acknowledgements

Same with the socket io for nodejs, you just need to add a callable as the last argument in the emit

Server

Client

With Timeout

Assign a timeout to each emit:

Add callback default arguments value for timeout

Listening

To listen to any event

Server Event

This event can't be use for the route Since this event are Swoole Websocket Event All Event with * should not be used

Rooms

In this package it was already included the rooms

To join to group just call the function join

To emit a message

Emit to multiple room

Leaving the room

Sending to specific user

In socket.io javascript, the user was automatically created a new room for each client sid.

But currently in this package it will not create a new room for each client.

In this package you just need to specify if its a room or a sid

Middleware

You can add an middleware for the server

To not continue the connection you just pass \Error in the $next

You can also add middleware for handshake event of Swoole Server. Just passed true to the second argument.

Also in callback it will pass the response for you to modify if you need it

If you want to create a middleware as a class we recommend to implement the Cydrickn\SocketIO\Middleware\MiddlewareInterface and if for handshake use Cydrickn\SocketIO\Middleware\HandshakeMiddlewareInterface

Example of middleware that use in handshake is the Cydrickn\SocketIO\Middleware\CookieSessionMiddleware. This middleware will create a session that uses the cookie and if the client did not send the session cookie then it will create a cookie and response it from the handshake.

Session

In this package the there is already session storage that you can use,

Using Swoole, session_start, $_SESSION should not be use since this function are global it stores the data in the process itself.

The session that provided here does not use this predefined session extensions. Currently, the session is define per connection so you can take the session via.

This getSession can return null if you don't have any middleware that creating the session.

To set a session

You can also customize your session storage, just implement the Cydrickn\SocketIO\Session\SessionStorageInterface

After creating your storage

You need to pass this in your server constructor

Example

TODO

This package was used in


All versions of socketio with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
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 cydrickn/socketio contains the following files

Loading the files please wait ....