Download the PHP package tiitoo/symfony3-nodesjssocket without Composer
On this page you can find all versions of the php package tiitoo/symfony3-nodesjssocket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package symfony3-nodesjssocket
Installation
Introduction
Bundle provides to emiting an events as live application and non-blocking javascript server and PHP emiters. Based on node.js, socket.io and elephant.io. Integrated packages with other vendor packages are included and binded to bundle.
Disclaimer
A bundle is origin from yii-node-socket extension on YiiNodeSocket and is rewriten for Symfony bundle package. Some of components are from orignal vendors such as socket.io, elephant.io, node.js and libraries from YiiNodeSocket.
Prerequisites
- PHP 5.2
- Symfony 2.6
- Nodejs package
- jQuery CDN
Install nodejs package on your system. Then find path of node and bind with node command. Find a node on a system:
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Activate a bundle by adding a follow bundle into AppKernel: app/AppKernel.php
file of your project:
Step 3: Cache and logs files
Make sure that in app directory cache and logs files are writeable. A bundle requires logs directory to store node socket emit and action events.
Step 4: Add configuration
Add a configuration attributes inside config.yml as sample:
Make sure that your hostname is same in your project from [yourhostname].
If you add origin server it should be in a lists from hosts and listener hosts.
By default node socket uses session storage and cookie to share information between server socket and client. A default name sessionVarName is PHPSESSID. If your application uses same session name change it to avoid conflicts.
When starting node socket it will store ID of system process into file. It uses for starting and stopping node.js services.
A service uses log file to store node events, triggers, callbacks, messages and status of node service. By default node starts as background service inside server.js file.
Step 5: Command event service
To staring a node server use console to activate service:
Get a console help intro:
Starting a service:
By default if service has already running it will show process ID of running service. You can stop or restart a service.
Terminating a service:
Restarting a service:
Restarting service will kill previously process if started and starting a new node service.
Check status and process ID of service:
If you encountering or if you prefer to manually start you can check your process id by using ps command to find node service:
Then find a symfony node service node server.js
and manually kill it using
Step 6: Put assets to your template resource
For loading socket.io and emiting events you need to put a template code inside head tag. Remove a jquery CDN if you already have in your template:
Before body tag put socket.io listener for incoming emits and status of socket:
A bundle requires in a web directory to include JS and CSS file you should check and include your files into web/bundles/reactorcodersymfony2nodesocket directory. To publish bundle into web directory and loading automaticaly use:
A public resource is located under Reactorcoder/Symfony2NodesocketBundle/Resources/public directory.
Step 7: Base class in controllers
In your controller (sending events):
Append a code after login function, load nodesocket class to register session and authenticate user into node socket. This should be done only once on login:
For receiving events use template.
Step 8: Emit global event
To send event message via socket using event name use:
Step 9: Emit user event
To send event message via socket using user ID and if you previously set SetUserId() on login use:
User will receive if is previously logged using createAuthenticationFrame() as user ID 2. A code sample is for authentication on Step 6.
To receive message just call template from Step 6.
Example
Full working sample demo is on Reactorcoder/Symfony2NodesocketBundle/Controller and Reactorcoder/Symfony2NodesocketBundle/Resources/views folder.
Contributing
Thank you for contributing, suggestions, coding and maintenances package that will helps others contributors, developers and end users. Feel free if you have suggestions, contributing or recommendations.