- Documentation: https://web.dev/articles/eventsource-basics
- Use case: broadcasting data from server to browsers
- Benefits:
- Easy to understand and implement (only a few lines of code)
- No library is needed
- Can use same HTTP(S) authentication as elsewhere in the app (which can’t be done with websockets)
<?php | |
if (!function_exists('dump')) { | |
function dump(...$args) | |
{ | |
$message = implode( | |
"\n\n", | |
array_map( | |
function($value) { | |
return var_export($value, true); |
-- Weigh rows against eachother based on different conditions, | |
-- ordering the results based on their given weights so that | |
-- more precise matches will show higher up in the results. | |
-- In this example, an exact match will show up at the top | |
-- of the results, a match at the beginning of the string | |
-- will show next, and a match anywhere will show last. | |
set @query = 'Liam'; |
<?php | |
// IP to check | |
$ip_check = $_SERVER['REMOTE_ADDR']; | |
// Array of allowed IPs and subnets, both IPv4 and IPv6 | |
$ips_allowed = array( | |
'192.30.252.0/22' | |
'2620:112:3000::/44' | |
'192.168.16.104' | |
); |
This document assumes you are building a traditional backend-heavy application as opposed to a frontend-heavy appliction which would typically use a framework like Angular or React. The use of these frameworks make this document irrelevant, however also require a change to your application architecture and a much larger overhead in order to get content onto a page, so as a simple way to build interactive web content a simple jquery based js stack will do fine.
It's important you use a directory structure which is impartial to your development environment, chosen server language (Python v. Java v. C# ...), and styling framwork (Twitter Bootstrap etc). This layer of separation means you can swap out the styles or the backend with minimal changes to the Js, simple and maintainable.
Here's an example from the project root:
In EcmaScript 2015 (ES6) the expression (x) => x * 2
means to create an anonymous function with one parameter x
that will return x * 2
. For example:
(x) => x * 2
// is equivalent to:
function(x) { return x * 2; }
A modified example from [documentation by Mozilla Developer Network][1] page demonstrates how they are useful:
var a = [
"Hydrogen",
<?php | |
define('PROCESSES_NUM', 6); | |
/** | |
* @param array $arr | |
* @param callable $func | |
*/ | |
function parallelForeach(array $arr, callable $func) | |
{ | |
$pid = null; |
#!/bin/bash | |
# Make sure you are up to date | |
yum -y update && yum -y install wget | |
# Install EPEL repository | |
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm | |
# Get us a clean working directory | |
mkdir /php |