Download the PHP package codemash/laravel-socket without Composer

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

Laravel Socket

This package allows you to use sockets easily and elegantly in your Laravel 5 application. Based on the awesome PHP socket library, Ratchet. Read the instructions below to get setup.

Requirements

Laravel 5.x.

Installation

You can install the package using the Composer package manager. You can install it by running this command in your project root:

Add the Codemash\Socket\SocketServiceProvider provider to the providers array in config/app.php':

Then, add the facade to your aliases array. The default facade provides an easy-to-use interface to integrate the socket files in your view.

Finally, the config and the javascript files need to be published, which can be done by running the following command:

The published assets can be found at config/socket.php and the default javascript at public/vendor/socket/socket.js. It is important to know that the Socket::javascript() facade function will include both a default socket located at window.appSocket and the socket.js source file located in the vendor folder. These are merely a start, and provide a quick way to work with the sockets but you are always free to write a custom implementation.

Getting started

Let's create a simple application that sends a message to all other connected clients. When a socket action occurs, it will be wrapped around a Laravel event and triggered. This is a great way for us to catch these events and act upon them. Let's register our listener in the app/Providers/EventServiceProvider.php file like this:

And create the listener at the following path: app/Listeners/MessageEventListener.php. Listeners provide 3 basic events. For our example here, we'll only be using the onMessageReceived event.

What the application above does, is the following: a connected client sends a message with the sendMessageToOthers command, which basically forwards the message to the rest of the connected clients on your application. It is important to note that a client is not the same as a User model. A client is simply a connection from someones browser to your Laravel application, no matter if that user is authed or not. There is a possibility to fetch the connected authentication model, more on that later.

Now it's time to write the client side, luckily the Socket facade takes care of that in no time. Create a blade template with the following content:

Finally, let's run the socket listener. You can do this by running the following artisan command in the project root:

Client connections

Using Eloquent models

Laravel Socket reads the session when available and maps the User eloquent model to your client. You can then retrieve the Eloquent model by using the following code:

Whenever you're using the clients list, like $event->clients, this is a Laravel Collection object. Methods such as filter, map, and so on, work very well on it.

Storing client related data

Client objects implement magic methods, meaning you can set any kind of additional properties during the life cycle of the server running. If you access a non existant property, it will however trigger an exception. Imagine you'd like to set a connected_at property containing the timestamp when the client connected. We'll add this property to the onConnected method in our event listener as seen below:

Production

Ubuntu provides the neat nohup tool, which runs processes on the background. In case you'd like to run your socket on a production server and you're on Ubuntu, you may always use the nohup tool to run the socket listener.

When using the jobs command, you'll see the socket running. It's easy to kill the process using the kill <pid> command. The process ID is listed in the jobs list.

Contributing

If you're having problems, spot a bug, or have a feature suggestion, please log and issue on Github. If you'd like to have a crack yourself, fork the package and make a pull request. Any improvements are more than welcome.


All versions of laravel-socket with dependencies

PHP Build Version
Package Version
Requires cboden/ratchet Version ^0.3.5
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 codemash/laravel-socket contains the following files

Loading the files please wait ....