amphp / getting-started Goto Github PK
View Code? Open in Web Editor NEWA getting started guide for Amp.
A getting started guide for Amp.
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 :(
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?
Redis needs an update to amphp/socket@^1
and then the last example here must be updated. See amphp/amphp.github.io#20.
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.