Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install Ratchet WebSockets for PHP on MAMP or XAMPP?

I'm trying to integrate a real time chat into my php / backbone app and I thought I would use ratchet? What do I need to do to install Ratchet into MAMP or XAMPP? The only documentation provided on their website is to use CURL, but I don't know how to install the necessary resources for localhost, nor do I know where those resources need to be add to. Any advice would be appreciated.

like image 396
Jason Biondo Avatar asked Mar 08 '13 03:03

Jason Biondo


People also ask

How configure WebSocket in php?

Create the HTTP Server Open the file app. php and add the following code: <? php use Ratchet\Server\IoServer; use Ratchet\Http\HttpServer; use Ratchet\WebSocket\WsServer; use MyApp\Socket; require dirname( __FILE__ ) .

What is ratchet WebSocket?

WebSockets for PHP Ratchet is a loosely coupled PHP library providing developers with tools to create real time, bi-directional applications between clients and servers over WebSockets.

Does php support WebSocket?

Yes, it's possible to do PHP + Websocket very simply, without any third party library (like Ratchet, often mentioned). You can find more detailed instructions about this here: How to create websockets server in PHP. It uses a constantly-running PHP server, that you start from command-line with php websockets.


1 Answers

You should install composer.phar in the root directory of your project.

If you are on linux you could simply run the command curl -s https://getcomposer.org/installer | php, otherwise you could use the windows installer from curl's download page

Once you have installed composer you have to create a 'composer.json' file where you will add all the dependencies needed for your project. If you only need Ratchet just paste this into your json file:

{
    "require": {
        "cboden/Ratchet": "0.2.*"
    }
}

Once you have done that, return to your terminal and run the command php composer.phar install.

This will install Ratchet and its dependencies on a newly created 'vendor' folder.

Now you could include Rathet in your php file in this way:

require __DIR__ . '/vendor/autoload.php';

That's all I think!

like image 149
Ingro Avatar answered Sep 22 '22 08:09

Ingro