amphp / socket

Non-blocking socket and TLS functionality for PHP based on Amp.

Home Page:https://amphp.org/socket

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The samples provided in the documentation don't work

alexmocanu opened this issue · comments

commented

The documentation needs to be updated. None of the provided examples seem to be working.

The code sample provided here https://amphp.org/getting-started/tcp-chat/basic-echo-server throws this error:
PHP Fatal error: Uncaught TypeError: Argument 1 passed to {closure}() must be an instance of Amp\Socket\ServerSocket, instance of Amp\Socket\ResourceSocket given, called in [REDACTED]vendor/amphp/amp/lib/functions.php on line 60 and defined in [REDACTED]/test.php:13

Same thing here: https://amphp.org/getting-started/tcp-chat/broadcasting - i only tried running the first code sample
PHP Fatal error: Uncaught TypeError: Argument 1 passed to class@anonymous::handleClient() must be an instance of Amp\Socket\ServerSocket, instance of Amp\Socket\ResourceSocket given, called in [REDACTED]/index.php on line 20 and defined in [REDACTED]/index.php:25

I think the documentation needs to be updated. None of the provided examples seem to be working.

The code sample provided here https://amphp.org/getting-started/tcp-chat/basic-echo-server throws this error:

PHP Fatal error: Uncaught TypeError: Argument 1 passed to {closure}() must be an instance of Amp\Socket\ServerSocket, instance of Amp\Socket\ResourceSocket given, called in [REDACTED]vendor/amphp/amp/lib/functions.php on line 60 and defined in [REDACTED]/test.php:13

Same thing here: https://amphp.org/getting-started/tcp-chat/broadcasting - i only tried running the first code sample

PHP Fatal error: Uncaught TypeError: Argument 1 passed to class@anonymous::handleClient() must be an instance of Amp\Socket\ServerSocket, instance of Amp\Socket\ResourceSocket given, called in [REDACTED]/index.php on line 20 and defined in [REDACTED]/index.php:25

Steps to reproduce:

  1. Create a new test directory:
    mkdir test; cd test
  2. Within that test directory download amphp/socket:
    composer require amphp/socket
  3. Create a test.php file, copy and paste one of the samples then execute the file with this command:
    php test.php
    This will start the script and wait for connections
  4. From another terminal try to connect with "nc":
    nc localhost 1337

As soon as nc attempts to connect the script will throw the errors mentioned above.

Tested on:

  • Ubuntu 18.04 with PHP 7.2.19 (installed from the distro's official repositories)
  • MacOS 10.14.6 with PHP 7.3.4 (installed with homebrew)

These are for the 0.10.x version, indeed. We've updated the socket docs, but didn't update the docs in the getting started guide yet, which is a separate repository. Thanks for the hint!

commented

I added this in the correct place here:
amphp/amphp.github.io#20 (comment)

I've updated all examples but the last one, so they should work properly with the latest version now. Thanks!