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

12,167

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!

Share:
12,167
Jason Biondo
Author by

Jason Biondo

Updated on June 04, 2022

Comments

  • Jason Biondo
    Jason Biondo almost 2 years

    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.

  • Jason Biondo
    Jason Biondo about 11 years
    ok, so I understand cURL is enabled by default, but does that mean I just open up a php file, add in curl -s getcomposer.org/installer | php to get composer and then run the page? Will that get me the dependencies I need. I really don't know anything about this kind of stuff and need some hand holding. I installed this via terminal on my web server, but I don't know how to do that locally.
  • Pacerier
    Pacerier about 10 years
    I've manualled downloaded composer.phar . I'm on a web server that doesn't allow running the command prompt, What other ways are there to use Ratchet?
  • Ingro
    Ingro about 10 years
    You should run composer install locally and then upload the resulting vendor folder to your remote host.
  • Pacerier
    Pacerier about 10 years
    Yea but after I've gotten all the files locally, I still need to start the websocket server on the public server. How do I start the server without access to the terminal?
  • Ingro
    Ingro about 10 years
    You could simply put the needed commands in a php file and hit that page with a browser or with cURL from your machine, anyway should the websocket server crash you'll have to manually start it again, so this is ideal just for testing or for learning purposes, for a real product you'll need a more manageable hosting I guess.
  • Pacerier
    Pacerier about 10 years
    That's not possible, local commands are of course disabled if called via php.