Giter VIP home page Giter VIP logo

getting-started's People

Contributors

bwoebi avatar ecolinet avatar jjok avatar joshdifabio avatar kelunik avatar krlv avatar orkin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

getting-started's Issues

Merging the chat server example and the event loop with tick() ?

Hello,

being new to the concepts of PHP's asynchronous programming, I read with very interest the https://amphp.org/getting-started/tcp-chat/ example, thank you very much for providing it.

Having done, unhappily, an app using JS socket.io for the html client and Node socket.io for the server, since I like PHP more, I decided to take the challenge to port the server to PHP with these concepts.

I wonder how and if would be possibile to merge a tick into the tcp chat server-like. For example where to put an "echo 'o'" in order to see the o's printed continuosly in the prompt window and at the same time listening for client's connections and managing their messages broadcast.

Should I use another [https://amphp.org/amp/event-loop/(amp/loop) somewhere? I Wouldn't know where to start to implement such a thing :(

A word about multithreading

Just by looking at this it got me wondering, however non-blocking it might be, it's still running on a single thread, right? Is there an easy way you can multithread this application?

Parse error: syntax error, unexpected '$socket' (T_VARIABLE) in D:\amphptest\server.php on line 14

Hello,

trying the server.php from https://amphp.org/getting-started/tcp-chat/basic-echo-server but got a syntax error upong execution:

Parse error: syntax error, unexpected '$socket' (T_VARIABLE) in D:\amphptest\server.php on line 14

The code as taken from the page above:

<?php
require __DIR__ . "/vendor/autoload.php";

// Non-blocking server implementation based on amphp/socket.

use Amp\Loop;
use Amp\Socket\Socket;
use function Amp\asyncCall;

Loop::run(function () {
    $uri = "tcp://127.0.0.1:1337";

    $clientHandler = function (Socket $socket) {
        while (null !== $chunk = yield $socket->read()) { // line 14 is here
            yield $socket->write($chunk);
        }
    };

    $server = Amp\Socket\Server::listen($uri);

    while ($socket = yield $server->accept()) {
        asyncCall($clientHandler, $socket);
    }
});

I have PHP 7.4.2 on a Windows 10 Pro 64bit environment.

(also, could you please drop a Windows equivalent for nc localhost 1337 for the lesson at https://amphp.org/getting-started/tcp-chat/?

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.