Code examples for presentation server-sent events
Run via nginx
| <?php | |
| // Adapted from: https://github.com/ratchetphp/Pawl | |
| require __DIR__ . '/vendor/autoload.php'; | |
| $loop = React\EventLoop\Factory::create(); | |
| $connector = new Ratchet\Client\Connector($loop); | |
| // For example: ws://127.0.0.1:9222/devtools/page/6c98af2a-8944-4742-91d3-154cbd873ce2 |
Code examples for presentation server-sent events
Run via nginx
Code examples for presentation server-sent events
php -S 127.0.0.1:9001
Then open with browser: http://127.0.0.1:9001
| #!/bin/sh | |
| echo -e "`date +'%Y-%m-%d %T.%N%z'` Starting Nginx..." | |
| CONFIG_SRC=/custom/config/site.conf | |
| CONFIG_DEST=/etc/nginx/conf.d/site.conf | |
| CONFIG_LOGS=/custom/logs | |
| # Replacing needed environment variables in config (envsubst will break $uri) | |
| # Store final config in logs, for easier debugging |
Visuals for prezentation: Being lazy in practice
| #!/bin/sh | |
| while true; do | |
| import -window root `date +%s-%N`.jpg | |
| sleep 1 | |
| done; |
Copy server-client.html into your server. E.g. it is http://aurelijus.banelis.lt/server-client.html
Run php -S localhost:12345 localhost-server.php
You should see 3 in http://localhost:12345/?a=1&b=2
You should see 1+2 = 3 when opened server-client.html on your own server.
| <?php | |
| require 'context.php'; | |
| $odd = array_flip(array_filter(array_flip($pairs), | |
| function($key) { return $key % 2 == 0; } | |
| )); | |
| $even = array_diff($pairs, $odd); | |
| $sumOdd = array_reduce($odd, Summation::$fSum); | |
| $sumEven = array_reduce($even, ['Summation', 'rSum']); |