I'm trying to learn now technology - reactPHP. But I'm stacked with starting script. I'd edited it little bit, but I have problem, if I call the react loop, the script is done twice.
I have this code:
<?php
require 'vendor/autoload.php';
$app = function ($request, $response) {
$date = new DateTime();
file_put_contents("data.txt", $date->getTimestamp().";", FILE_APPEND);
$response->writeHead(200, array('Content-Type' => 'text/plain'));
$response->end("Done\n");
};
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket, $loop);
$http->on('request', $app);
echo "Server running at http://127.0.0.1:1337\n";
$socket->listen(1337);
$loop->run();
and if I call http://localhost:1337/react/index.php I get in data.txt this
1439849018;1439849018;
I'm expecting only one value.
I have tested your code and the problem is because your'e testing it in your browser. Your browser send request and then ask for favicon. That's it. On the image from Inspect it's the first and third line. Next time try to run the scripts from cmd.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With