PHP Ratchet WebSocket server using PHP Chess.
Read the latest docs here.
Check out this demo.
Clone the chesslablab/chess-server
repo into your projects folder as it is described in the following example:
git clone [email protected]:chesslablab/chess-server.git
Then cd
the chess-server
directory and install the Composer dependencies:
composer install
Create an .env
file:
cp .env.example .env
Finally, you may want to add the following entry to your /etc/hosts
file if running the PHP chess server on your localhost along with React Chess as per the REACT_APP_WS_HOST
variable defined in the react-chess/.env.example file.
127.0.0.1 pchess.net
The chess server comes in four different flavors and can be run using a PHP script.
Script | Description | Use |
---|---|---|
cli/testing.php | TCP socket. | Functional testing. |
cli/dev.php | Simple WebSocket server. | Development. |
cli/staging.php | Secure WebSocket server. | Staging. |
cli/prod.php | Secure WebSocket server. | Production. |
Run the TCP socket server.
php cli/testing.php
Run the functional tests.
vendor/bin/phpunit tests/functional
PHPUnit 9.6.11 by Sebastian Bergmann and contributors.
Runtime: PHP 8.2.9
Configuration: /home/standard/projects/chess-server/phpunit.xml
.. 2 / 2 (100%)
Time: 00:00.042, Memory: 8.00 MB
OK (2 tests, 2 assertions)
Run the simple WebSocket server if you are not using an SSL/TLS certificate.
php cli/dev.php
Before starting the secure WebSocket server for the first time, make sure to have created the certificate.crt
and private.key
files into the ssl
folder.
Run the staging secure WebSocket server if you don't want to check the website's origin.
php cli/staging.php
This will allow any origin to send a request to it.
Before starting the secure WebSocket server for the first time, make sure to have created the certificate.crt
and private.key
files into the ssl
folder.
Run the secure WebSocket server to check the website's origin as defined in the WSS_ALLOWED
variable in the .env.example
file.
php cli/prod.php
This will allow the WSS_ALLOWED
website to send a request to it.
Alternatively, the chess server can run on a Docker container.
docker compose -f docker-compose.testing.yml up -d
docker compose -f docker-compose.dev.yml up -d
docker compose -f docker-compose.staging.yml up -d
docker compose -f docker-compose.prod.yml up -d
Open a console in your favorite browser and run the following commands:
const ws = new WebSocket('wss://pchess.net:8443');
ws.send('/start classical fen');
The GNU General Public License.
See the contributing guidelines.
Happy learning and coding!