Download the PHP package artisansdk/server without Composer

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

Server

A service-based, Laravel PHP implementation of an async, realtime, WebSocket server.

Table of Contents

Installation

The package installs into a Laravel application like any other Laravel package:

Then in your Laravel application's config/app.php add the ArtisanSDK\Server\Provider::class to the providers key. This will register the configs and Artisan commands provided by the package. You can publish these configs to config/server.php by running:

Show Me: You can see how to integrate this package by browsing the source code of larandomizer/app which is a full featured prize give away app for meetups and conferences.

Configure the Environment

You will still want to edit the .env file to customize environment settings. Note that no database is used as all data is stored in memory on the server. Restarting the server will cause all data to be lost. Below are available options for server customization:

Nginx Websocket Proxy Configuration

Nginx makes the perfect lightweight frontend server for the Laravel backend application. Additionally it can be used to proxy websockets connecting on port 80 to the 8080 default server socket. Doing so helps get around some firewall settings. The following should be placed just before your default location directive for the Laravel application itself (e.g.: Forge's default). Using these settings you can host websockets securely with the wss:// protocol allowing Nginx to handle the SSL connection and your websocket server handling basic HTTP.

A quick note on the settings used:

Running the Server

The websocket server can be ran as an console command using php artisan server:start and if you pass --help to the command you can see additional options. You can stop the running server by killing the process with CMD + C (or CTRL + C).

In production you would want to have Supervisor monitor the server and restart it if ever it crashes. The demo application has a "Restart Server" command which actually just stops the server and expects Supervisor to start it again automatically. If you are using Laravel Forge this is pretty easy to do by adding a New Deamon on the server with a configuration of:

The resulting Supervisor config might be:

Forge does not add the startsecs by default but in practice this may be needed to give the server ample time to start without hard exiting and forcing Supervisor to give up on starting the process.

Usage Guide

Extending the Server Manager

The WebSocket server is a singleton instance that wraps brokers all connections and messages between connected clients and the server via Broker. While this class rarely needs modification, the broker collaborates with the Manager class. You can think of the manager as the kernel of the application as it maintains the initial boot state and event loop the entire time the server is running. It has sensible defaults but will likely need extending for anything domain specific.

Simple create a new manager class in your local namespace such and include a boot() method which will be called to initialize your application's custom listeners:

As you can see in this example it's a good idea to call the parent boot() method if you want to maintain the existing behavior and simply add on new behavior. With the class extended, you now just need to update the configuration setting in app/server.php under the key server.manager to App\Manager::class so the server knows which manager to use:

Pushing Messages to the Realtime Queue

By default the ArtisanSDK\Server\Manager@boot() method adds a queue worker to the async event loop so that "offline" messages can be sent to the "realtime" connected websocket clients. You can use any async driver (basically don't use sync as the queue driver) but if you are using Laravel Forge it is pretty easy to use beanstalkd driver. Set SERVER_QUEUE_DRIVER and SERVER_QUEUE in your .env to configure the driver and queue name for your realtime messages.

To send messages from your "offline" code (e.g.: controllers, repositories, etc.) to your "realtime" code you can use ArtisanSDK\Server\Traits\WebsocketQueue trait in your caller class and then call $this->queue(new Command) to push server commands into the event loop of the websocket server. Commands should run nearly instantly though there can be some lag depending on remaining commands within the event loop. You can tweak the timing of the worker in ArtisanSDK\Server\Manager@boot() method's configuration of the worker.

Authenticating Client Messages

There is a basic auth scheme in place which allows the server to PromptForAuthentication against a connection and then remember that the connection is authenticated. This simplifies further message processing and relies on any ClientMessage that must be authenticated to implement the authorize() method. There are three basic traits that can be used on any message to achieve a couple of common strategies:

Licensing

Copyright (c) 2023 Artisan Made

This package is released under the MIT license. Please see the LICENSE file distributed with every copy of the code for commercial licensing terms.


All versions of server with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.4
cboden/ratchet Version ~0.3.6
illuminate/bus Version ~5.4
illuminate/contracts Version ~5.4
illuminate/support Version ~5.4
ramsey/uuid Version ~3.5
react/child-process Version ~0.4.3
wyrihaximus/react-guzzle-psr7 Version ~2.0
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 artisansdk/server contains the following files

Loading the files please wait ....