This document discusses the history and technologies behind Facebook. It notes that Facebook was originally founded by Mark Zuckerberg in 2004 as a social network for Harvard students. As it grew, Facebook transitioned to using PHP for server-side scripting and developed its own technologies like HHVM (Hip Hop Virtual Machine) and the Hack programming language to improve performance and security. Key points discussed include Facebook's use of PHP, its development of a PHP to C++ transpiler called HPHPc, its creation of a JIT compiler called HHVM, and its development of the Hack language which combines elements of PHP and C++.
Slides from a presentation given at Laravel Chicago on November 18, 2014. Goes over the basics of building a REST API using the Laravel framework as well as some handy tips and tools.
Setting up the Red5 environment, building sample applications and integrating with flash. We will look at how Red5 works within the flash IDE and build a sample chat application, video streaming, and multi-user environment.
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Edureka!
** Python Certification Training: https://www.edureka.co/python **
This Edureka Python Flask tutorial will cover all the fundamentals of Flask. It will also explain how you can develop your own website using Flask in Python.
Introduction to Flask
Installing Flask
Flask Application
Routing in Flask
Variable Rules in Flask
URL Binding in Flask
HTTP Methods using Flask
Templates in Flask
Static Files in Flask
Request Objects in Flask
Cookies in Flask
Redirects and Errors in Flask
Flask Extensions
Conclusion
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Slides of my talk I gave @ PyRE.it in ReggioEmilia about developing a Rest Api in Python using a little bit of Flask and SqlAlchemy.
www.pyre.it
www.alessandrocucci.it/pyre/restapi
Slides from a presentation given at Laravel Chicago on November 18, 2014. Goes over the basics of building a REST API using the Laravel framework as well as some handy tips and tools.
Setting up the Red5 environment, building sample applications and integrating with flash. We will look at how Red5 works within the flash IDE and build a sample chat application, video streaming, and multi-user environment.
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Edureka!
** Python Certification Training: https://www.edureka.co/python **
This Edureka Python Flask tutorial will cover all the fundamentals of Flask. It will also explain how you can develop your own website using Flask in Python.
Introduction to Flask
Installing Flask
Flask Application
Routing in Flask
Variable Rules in Flask
URL Binding in Flask
HTTP Methods using Flask
Templates in Flask
Static Files in Flask
Request Objects in Flask
Cookies in Flask
Redirects and Errors in Flask
Flask Extensions
Conclusion
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Slides of my talk I gave @ PyRE.it in ReggioEmilia about developing a Rest Api in Python using a little bit of Flask and SqlAlchemy.
www.pyre.it
www.alessandrocucci.it/pyre/restapi
RESTful APIs are useful when developing a modern web application since they allow for multiple possibilities for collaboration with third-party software as well as multiple types of front-ends, such as mobile apps and HTML5 web applications. The creation of RESTful API’s is facilitated using Laravel 4, a PHP 5.3 Framework that is rapidly growing in popularity. Laravel’s features such as the facade pattern allow for easy-to-read code and expressive ORM statements.
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiJérémy Derussé
Le moyen le plus rapide d'obtenir une réponse d'un Backend est de ne pas l'appeler ;-) Une solution fournie par les "reverse-proxy" me direz-vous, mais pas si simple d'invalider le cache...
Ce talk aborde une fonctionnalité méconnue de Varnish: les tags. Nous verrons comment en tirer partie via les "event listeners" d'une application Symfony standard. Au menu, un cluster de Rasberry Pi, une API, et des données toujours fraîches sous la milliseconde.
Web service with Laravel:
Laravel Philosophy
Requirement
Installation
Basic Routing
Requests & Input
Request Lifecycle
Controller
Controller Filters
RESTful Controllers
Database Model using Eloquent ORM
Creating A Migration
Code Example
Handling RESTful API requests with Laravel PHP Framework resource controllers is already very easy. With Laravel 5, handling request routing has been made even easier by using a configuration-as-annotation approach. Controller annotations may take advantage of doc block-style syntax and then be compiled using Laravel's artisan command-line tool. I'll present this approach by providing a few examples and discussing some of the pros and cons.
Creating a modern web application using Symfony API Platform, ReactJS and Red...Jesus Manuel Olivas
The API Platform framework is a set of tools to help you building API-first projects. The API project Platform is built on top of the Symfony framework, it means you can reuse all your Drupal 8 and Symfony skills and benefit of the incredible amount of Symfony documentation and community bundles.
During this session, you will learn how to use the API Platform project to create a modern web application using Symfony, Doctrine, ReactJS, Redux, Redux-Saga, Ant Design and DVA.
Les web-services sont aujourd'hui au centre des SI de nos entreprises. Ils permettent de transmettre l'information entre des systèmes hétérogènes, à la fois au sein de l’entreprise mais également à l'extérieur, notamment et de plus en plus vers des systèmes mobiles. Or exposer cette information, potentiellement critique, pose la question de la sécurisation de ces échanges. Cette présentation sera l'occasion de présenter JWT, d'expliquer son fonctionnement et son implémentation au sein d'un projet Symfony 3.
Learn about some of the new features in Laravel 5, with a focus on the command pipeline, including a few opinions about how to use the pipeline in the best possible way to enforce a solid separation of concerns.
Building Single Page Application (SPA) with Symfony2 and AngularJSAntonio Peric-Mazar
Forget about classic website where UX is not so important. We are living in time where usability is one of the important thing if you are building some business client oriented web service. How to connect Symfony2 as backend and AngularJS as frontend solution? What are best practices? What are disadvantageous? How to take best from both worlds? These are topics I will cover in my talk with real examples.
PHP remains the most popular server-side language on the Web and the most favoured language for Web attacks. The security vulnerabilities and attack techniques become more sophisticated though. For example, the vulnerability types PHP Object Instantiation and Phar Deserialization are comparatively unknown to traditional types like XSS and SQLi. In this technical talk, we look at a couple of critical security bugs found in popular open source PHP applications, such as WordPress, WooCommerce and Shopware. We will focus on fundamental design flaws and new state-of-the-art exploitation techniques that are used by attackers to compromise web servers through these issues which can occur in any other application as well.
In this presentation you are going to learn about basics of Web and php mysql web development. we discover about What is world wide web? How client server works? Why PHP is important? and basics of PHP like installation, variables, operators, conditional statements and loops.
RESTful APIs are useful when developing a modern web application since they allow for multiple possibilities for collaboration with third-party software as well as multiple types of front-ends, such as mobile apps and HTML5 web applications. The creation of RESTful API’s is facilitated using Laravel 4, a PHP 5.3 Framework that is rapidly growing in popularity. Laravel’s features such as the facade pattern allow for easy-to-read code and expressive ORM statements.
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiJérémy Derussé
Le moyen le plus rapide d'obtenir une réponse d'un Backend est de ne pas l'appeler ;-) Une solution fournie par les "reverse-proxy" me direz-vous, mais pas si simple d'invalider le cache...
Ce talk aborde une fonctionnalité méconnue de Varnish: les tags. Nous verrons comment en tirer partie via les "event listeners" d'une application Symfony standard. Au menu, un cluster de Rasberry Pi, une API, et des données toujours fraîches sous la milliseconde.
Web service with Laravel:
Laravel Philosophy
Requirement
Installation
Basic Routing
Requests & Input
Request Lifecycle
Controller
Controller Filters
RESTful Controllers
Database Model using Eloquent ORM
Creating A Migration
Code Example
Handling RESTful API requests with Laravel PHP Framework resource controllers is already very easy. With Laravel 5, handling request routing has been made even easier by using a configuration-as-annotation approach. Controller annotations may take advantage of doc block-style syntax and then be compiled using Laravel's artisan command-line tool. I'll present this approach by providing a few examples and discussing some of the pros and cons.
Creating a modern web application using Symfony API Platform, ReactJS and Red...Jesus Manuel Olivas
The API Platform framework is a set of tools to help you building API-first projects. The API project Platform is built on top of the Symfony framework, it means you can reuse all your Drupal 8 and Symfony skills and benefit of the incredible amount of Symfony documentation and community bundles.
During this session, you will learn how to use the API Platform project to create a modern web application using Symfony, Doctrine, ReactJS, Redux, Redux-Saga, Ant Design and DVA.
Les web-services sont aujourd'hui au centre des SI de nos entreprises. Ils permettent de transmettre l'information entre des systèmes hétérogènes, à la fois au sein de l’entreprise mais également à l'extérieur, notamment et de plus en plus vers des systèmes mobiles. Or exposer cette information, potentiellement critique, pose la question de la sécurisation de ces échanges. Cette présentation sera l'occasion de présenter JWT, d'expliquer son fonctionnement et son implémentation au sein d'un projet Symfony 3.
Learn about some of the new features in Laravel 5, with a focus on the command pipeline, including a few opinions about how to use the pipeline in the best possible way to enforce a solid separation of concerns.
Building Single Page Application (SPA) with Symfony2 and AngularJSAntonio Peric-Mazar
Forget about classic website where UX is not so important. We are living in time where usability is one of the important thing if you are building some business client oriented web service. How to connect Symfony2 as backend and AngularJS as frontend solution? What are best practices? What are disadvantageous? How to take best from both worlds? These are topics I will cover in my talk with real examples.
PHP remains the most popular server-side language on the Web and the most favoured language for Web attacks. The security vulnerabilities and attack techniques become more sophisticated though. For example, the vulnerability types PHP Object Instantiation and Phar Deserialization are comparatively unknown to traditional types like XSS and SQLi. In this technical talk, we look at a couple of critical security bugs found in popular open source PHP applications, such as WordPress, WooCommerce and Shopware. We will focus on fundamental design flaws and new state-of-the-art exploitation techniques that are used by attackers to compromise web servers through these issues which can occur in any other application as well.
In this presentation you are going to learn about basics of Web and php mysql web development. we discover about What is world wide web? How client server works? Why PHP is important? and basics of PHP like installation, variables, operators, conditional statements and loops.
PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. As of January 2013, PHP was installed on more than 240 million websites (39% of those sampled) and 2.1 million web servers.[4] Originally created by Rasmus Lerdorf in 1994,[5] the reference implementation of PHP (powered by the Zend Engine) is now produced by The PHP Group.[6] While PHP originally stood for Personal Home Page,[5] it now stands for PHP: Hypertext Preprocessor, which is a recursive backronym
PHP / MySQL applications are compatible to all operating systems, support all the popular databases, 100% remotely configurable, perfect for web programming & provide higher performance and speed.
PHP is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dynamically generated pages quickly.
MySQL is a Relational Database Management System (RDBMS) that uses Structured Query Language (SQL).
PHP is the most popular scripting language for web development. It is free, open source and server-side (the code is executed on the server).
PHP third party tool and plug-in integration such as chat, forum, blog and search engine
Implémentation efficace et durable de processus métiers complexesGeeks Anonymes
La transposition de processus métiers complexes en programmes informatiques est parfois difficile pour des raisons techniques et/ou communicationnelles. Le faire efficacement et sous une forme flexible l'est encore plus. Pousse-Café, un framework Java se basant sur le Domain-Driven Design (DDD), rend la tâche plus abordable. https://www.pousse-cafe-framework.org/
Par Gérard Dethier, aux Geeks Anonymes du 15 janvier 2021
Vidéo : https://youtu.be/DE0QpTIz1cQ
Conférence des Geeks Anonymes sur " Reprendre le contrôle de ses données ", par Gérard Dethier, le 26 octobre 2020.
Vidéo : https://youtu.be/RUbZ9RbI7TA
Conférence des Geeks Anonymes sur " le langage Go ", par Thomas Hayen le 23 septembre 2020.
Cette conférence est disponible en vidéo sur Youtube : https://youtu.be/AlGGneVGTJk
Instagram has become one of the most popular social media platforms, allowing people to share photos, videos, and stories with their followers. Sometimes, though, you might want to view someone's story without them knowing.
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfFlorence Consulting
Quattordicesimo Meetup di Milano, tenutosi a Milano il 23 Maggio 2024 dalle ore 17:00 alle ore 18:30 in presenza e da remoto.
Abbiamo parlato di come Axpo Italia S.p.A. ha ridotto il technical debt migrando le proprie APIs da Mule 3.9 a Mule 4.4 passando anche da on-premises a CloudHub 1.0.
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC
Ellisha Heppner, Grant Management Lead, presented an update on APNIC Foundation to the PNG DNS Forum held from 6 to 10 May, 2024 in Port Moresby, Papua New Guinea.
Italy Agriculture Equipment Market Outlook to 2027harveenkaur52
Agriculture and Animal Care
Ken Research has an expertise in Agriculture and Animal Care sector and offer vast collection of information related to all major aspects such as Agriculture equipment, Crop Protection, Seed, Agriculture Chemical, Fertilizers, Protected Cultivators, Palm Oil, Hybrid Seed, Animal Feed additives and many more.
Our continuous study and findings in agriculture sector provide better insights to companies dealing with related product and services, government and agriculture associations, researchers and students to well understand the present and expected scenario.
Our Animal care category provides solutions on Animal Healthcare and related products and services, including, animal feed additives, vaccination
2. Introduction Server-side scripting Client-side scripting Thrift Databases
Once a pony time. . .
The“face book”was the official printed book or web directory
consisting of individuals’ photographs and names, given to students.
On October 23, 2003 Harvard student Zuckerberg launches
Facemash.com: rate other people’s attractiveness. Shut down within
days. Zuckerberg faced expulsion for breaching security, violating
copyrights and individual privacy because he stole the student pictures
from the face book to populate Facemash.
On February 4, 2004 Zuckerberg and fellow Harvard students launch
TheFacebook.com, an unofficial online face book of Harvard
university students, with no material stolen from Harvard.
Users could search for other people and had privacy options to
prevent e.g. their name from being searched, to prevent student
outrage as for Facemash.
After one month, half of the Harvard undergraduate students had a
profile.
3. Introduction Server-side scripting Client-side scripting Thrift Databases
Once a pony time. . .
TheFacebook was promptly extended to other Boston universities and
eventually all US universities.
It dropped the“The”and became“Facebook”in August 2005.
Worldwide universities spread.
In September 2006, network extented beyond educational institutions
to anyone aged 13 with an email address.
On May 4th, 2017 Facebook reaches 2bn users.
4. Introduction Server-side scripting Client-side scripting Thrift Databases
Server-side scripting language – the choice of PHP
FB uses PHP as the server-side scripting language to generate HTML.
Despite its flaws and slowness, PHP is still by far the most used
among server-side scripting languages.
Nowadays, viable alternatives exist, but at the time, PHP was a good
choice for FB.
When FB faced scaling issues, their PHP codebase was already
several millions lines of code long.
FB kept and improved PHP instead of trying to rewrite their whole
codebase into another language.
5. Introduction Server-side scripting Client-side scripting Thrift Databases
HPHPc – PHP-to-C++ transpiler
The default PHP execution engine is Zend, an interpreter.
In November 2007, FB starts experiments to convert (transpile) PHP
code to C++, to compile it with a regular C++ compiler.
Called HPHPc, in 2009 it became FB’s sole execution engine
powering FB’s web servers.
FB adds HPHPd to allow developers to use break points, watches etc.
In early 2010, HPHPc open sourced as“Hip Hop for PHP”.
HPHPc was performant, but FB still needed something faster.
In 2010, FB started working on JIT compilation called HHVM.
HHVM took over FB’s entire web fleet in early 2013.
HPHPc is not deployed anywhere anymore.
6. Introduction Server-side scripting Client-side scripting Thrift Databases
HHVM – JIT compilation
HHVM stands for Hip Hop Virtual Machine (pretty much like what JVM is
for Java).
Why a Virtual Machine? This is unrelated with VMWare, VirtualBox and
the rest, which perform hardware virtualization.
The JVM compiles a Java source code to an intermediate language called
the Java Bytecode. A CPU cannot execute bytecode (it is not machine
code). The JVM translates the Java Bytecode to machine code. The JVM
actually defines an abstract CPU, or virtualizes the CPU.
The HHVM compiles PHP source code into Hip Hop Bytecode (HHBC).
Why an intermediate step? JIT (Just-in-Time) compilation of bytecode
allows adaptive optimization which can yield faster execution than static
compilation.
7. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack
FB developed Hack, an evolution of PHP, tailored for the HHVM. Hack
mainly allows to use both dynamic and static typing:
function division(float $a, int $b) : float {
return $a / $b;
}
FB does not rewrite its PHP codebase into Hack. Old PHP code is kept.
New code is written in Hack. Hack code can call PHP code (and vice
versa). The HHVM runs both PHP and Hack. Hack deployed in
production in June 2012.
Hack’s code check tool was coined the“typechecker”(command
hh_client file.hh).
Hack is not a superset of PHP. Most bad PHP features are purposely
forbidden in Hack.
8. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – static styping
PHP 5.x actually allowed typehints, but for class types only:
function enroll(Student $student, School $school) {
echo ’Enrolling ’ . $student->name . ’ in ’ . $school->name;
}
enroll(new Student("Damien"), new Program("Medicare"));
// Argument 2 passed to enroll() must be an instance of School.
Typehints of primitive types were not allowed in PHP 5.x:
function stringTest(string $str) { echo $str; }
stringTest(’definitely a string’); // Argument 1 passed to
// stringTest() must be an instance of string, string given.
Hack supports all typehints, for function parameters and return type.
9. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – static styping
Static typing for class properties:
class C {
public static int $loggingLevel_ = 2;
private string $name_;
}
However, the type of local variables cannot be specified:
$x = 10;
$x = ’ten’; // valid
In Hack, local variables do not have types; local variables hold values,
which have types. At any point in the program, the typechecker knows
which type of value each variable holds. If a new value is assigned to a
variable, the typechecker will update its knownledge.
10. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – multiple possible types
How to deal with
if(some_condition())
$x = 10; // int
else
$x = ’ten’; // string
The typechecker remembers that $x can be either an int or a string. The
following operations must support both int and string:
echo $x; // ok: can echo an int or a string
echo $x+20; // error: incompatible with a string
11. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – type inference
Type inference is type guessing when there is no annotation (no type
specified). Type inference is only function-local. When analyzing a
function and performing type inference, the typechecker never propagates
its guesses to called functions or caller functions.
function f($str) {
return ’Here is a string:’ . $str;
}
function main() {
echo f(’boo!’);
}
main();
We can infer the return type of f to be only a string. The typechecker will
not check main’s code with the known returned type of f.
12. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – type inference
1 An inferred parameter or return type may impact numerous other
functions. This is not affordable considering FB’s large codebase. The
typechecker must run quickly. An inferred type is only used to check
the code of the current function, not called of caller functions.
2 If the types are specified, the typechecker only needs to check at most
the directly called and caller functions, not the whole tree of called
and caller functions, which puts a fairly low cap on the work required.
13. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – number of parameters
PHP allowed
function f($a, $b) { }
f(1,2,3);
$a receives 1 and $b receives 2, third argument is forgotten. This is
accepted by PHP although the developer obviously made a mistake, which
may be tough to find. Hack forbids this.
14. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – default values
Hack allows default values for arguments:
function f(string $str = ”, int $i = 0) { }
However, Hack forbids a null default value, whereas PHP allowed it:
function f(SomeClass $obj = null) { }
null is not really a default value. It depicts the lack of value. Hack forces
to declare the parameter nullable with
function f(?SomeClass $obj = null) { }
f();
15. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – default values
Example with a nullable string:
function takes_string(string $str) { }
function takes_nullable_string(?string $str) {
if($str !== null) {
takes_string($str);
}
}
takes_nullable_string(null);
takes_nullable_string(’hello’);
!is_null($str) may also be used instead of $str !== null.
The if is mandatory. Inside the if, the typechecker sees that $str is not
null, so takes_string can be called.
16. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – generics, arrays, tuples
function max_and_index(array<float> $items) : (float, int) {
$max = -INF;
$maxIndex = -1;
foreach($items as $index => $value) {
if($value > $max) {
$max = $value;
$maxIndex = $index;
}
}
return tuple($max, $maxIndex);
}
Tuples are actually a restricted version of arrays.
Hack also introduced new collections (Vector, Set and Map) on top of
PHP’s array.
17. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Callables
Pass function to a parameter:
function do_work(array<float> $items,
(function(int,float):string) $fct)
{
foreach($items as $index => $value) {
echo $fct($index, $value);
}
}
In PHP, a function passed as a parameter was a callable. Under the
hood, $fct is just an object. What can be done in Hack can be done in
PHP. Hack just gives ways to better express programs.
R
18. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Enumeration
PHP has no enums. Class constants or global constants had to be used.
enum CardSuit : int {
SPADES = 0; HEARTS = 1; CLUBS = 2; DIAMONDS = 3;
}
function suit_symbol(CardSuit $suit) : string {
switch($suit) {
case CardSuit::SPADES :
return "xe2x99xa4";
case CardSuit::CLUBS :
return "xe2x99xa7";
}
}
The typechecker reports“Switch statement nonexhaustive; the following
cases are missing: HEARTS, DIAMONDS”. default can also be used.
19. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Switch statement
In switch statements, PHP allows multiple default statements.
Forbidden in Hack.
The developer must not forget break; at the end of a case. Hack
returns an error if no break; specified, unless the case is empty. If
fallthrough is intentional,“// FALLTHROUGH”must be added.
20. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Shape
In PHP, most of the time, to represent a user with an id and a name, we do
not use a class with two properties, but an array with keys“id”and“name”.
Arrays shapes are meant to tell the Hack typechecker about the structure
of such an array:
type user = shape(’id’ => int, ’name’ => string);
function make_user(int $id, string $name) : user {
return shape(’id’ => $id, ’name’ => $name);
}
function make_user_2(int $id, string $name) : user {
$user = shape();
$user[’id’] = $id;
$user[’name’] = $name;
return $user;
}
21. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Closures and lambdas
Closure with array_map (PHP and Hack):
$id_to_user = [1=>’Mr1’, 2=>’Mr2’, 3=>’Mr3’, 4=>’Mr4’];
$user_ids = [2, 4];
$user_names = array_map(
function($id) use ($id_to_user) { return $id_to_user[$id]; },
$user_ids
);
The closure can be rewritten as a lambda expression in Hack:
$user_names = array_map($id ==> id_to_user[$id], $user_ids);
R
22. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Typechecker modes
PHP code is started with <?php. In Hack, it is <?hh with the choice of
mode.
1 Declarative mode: <?hh // decl
2 Partial mode: <?hh
3 Strict mode: <?hh // strict
R
23. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Declarative mode
Declarative mode : <?hh // decl
The typechercker does not check the static types. The typechecker only
checks for invalid syntax.
The declarative mode is a transition aid if one is migrating an existing
PHP codebase to Hack.
The HHVM/Hack package also provides tools to help migrate PHP code
to Hack, and Hack to PHP (if some users want to write in Hack but
cannot use HHVM for example).
R
24. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Partial mode
Partial mode : <?hh
The typechercker does all the typechecking it can, but does not require
typehints.
Top–level code is allowed but not typechecked. This is because top-level
code requires globals. Code should be wrapped in a function and have only
one top-level statement be a call to that function.
function main() {
// ...
}
main(); // top-level statement
R
25. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Strict mode
Strict mode : <?hh // strict
Anywhere there can be a type annotation, it must be specified, with a few
exceptions: constructors and destructors (no return type) and closures.
Strict mode cannot call PHP, whereas partial and declarative modes can.
But strict mode can call partial-mode or decl-mode Hack code.
In all web apps, there has to be at least one top-level statement to serve
as an entry point. So there will always be at least one partial-mode file.
If the code is 100% strict, it should be impossible to incur a type error at
runtime in the HHVM.
R
26. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Accessing superglobals
Strict mode does not allow superglobals. Accessor must be written in a
partial-mode file, called from strict-mode files.
function get_params() : array { return $_GET; }
But this does not contribute to any type safety. We should write instead
function get_param(arraykey $key) : ?string {
if(!array_key_exists($key, $_GET)) { return null; }
$value = $_GET[$key];
return is_string($value) ? $value : null;
}
Better: replace the return statement with
invariant(is_string($value), ’get_param: Expected string’);
return $value;
R
27. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Special attributes
There are several attributes (decorators) which can be written in front of
methods, e.g. <<__Override>> to report an error if there is no function
override.
R
28. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Special attributes
Common implementation to cache the result of a time-consuming
computation:
function factorize_impl($num) {
// some factorization algorithm
}
function factorize($num) {
static $cache = [];
if(!isset($cache[$num]))
$cache[$num] = factorize_impl($num);
return $cache[$num];
}
29. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Special attributes
HHVM handles the caching of functions results declared with the
<<__Memoize>> special attribute:
<<__Memoize>>
function factorize($num) {
// some factorization algorithm
}
HHVM makes no garantee that all results are kept forever. HHVM may
delete entries from the cache to free up memory.
30. Introduction Server-side scripting Client-side scripting Thrift Databases
Memcached
Memcached is an open-source (not developed by FB) distributed memory
caching system, to exploit unused RAM of multiple computers.
Facebook has around 300TB of data in Memcached processes. Memcached
is also used by YouTube, Reddit, Twitter, Tumblr, Wikipedia etc.
Most cloud providers sell Memcached services at part of their Platform as
a Service (PaaS), including Google App Engine, Amazon ElastiCache, IBM
Bluemix and Microsoft Azure.
Memcached can be used through Hack’s async capabilities.
31. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – async
Hack’s async capabilities offer a way to use cooperative multitasking, in
which tasks voluntarily and explicitely cede the CPU to one another.
async function do_work() : Awaitable<string> {
// time-consuming computation
return ’ok’;
}
async function main() {
$msg = await do_work();
echo $msg;
}
await tells the HHVM to wait for the function result to be available.
await yields to another suspended async function, if there is any.
do_work() does not return a string. It returns an object that represents
a string which may or may not be available.
32. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – async
HHVM provides await extensions for four kinds of operations:
1 queries to MySQL databases;
2 queries to Memcached;
3 reads and writes of stream resources;
4 cURL requests.
33. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – MySQL query
async function fetch_db(int $id) : Awaitable<string> {
$conn = await AsyncMysqlClient::connect(localhost, 3306,
’dbname’,’admin’,’pass’);
$result = await $conn->queryf(
’SELECT name FROM users WHERE id=%d’, $id);
return $result->mapRows()[0][’name’];
}
queryf automatically performs appropriate escaping, to prevent SQL
injection attacks.
34. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – cURL request
async function fetch_web() : Awaitable<string> {
return await HHAsiocurl_exec(’https://www.example.com’);
}
Await multiple asynchronous operations and resume when all the results
are available:
async function fetch_all() : Awaitable<string> {
list($web, $db) = await HHAsiov(
array(fetch_web(), fetch_db(2)));
return $web . $db;
}
35. Introduction Server-side scripting Client-side scripting Thrift Databases
Hack – Memcached
Memcached is used through MCRouter, an open-source project developed
by FB to aid in scaling a Memcached deployment.
async function fetch_name(MCRouter $mcr, int $id) :
Awaitable<string>
{
$cachedResult = await $mcr->get($id);
if($cachedResult->isSucceeded()) {
return $cachedResult->getResult();
}
else {
$name = await fetch_db($id);
await $mcr->set($id, $name);
return $name;
}
}
36. Introduction Server-side scripting Client-side scripting Thrift Databases
XHP
XHP: represent an HTML tree as PHP/Hack objects, by means of
embedded XML-like syntax.
function build_paragraph(string $text, string $style): :div {
return <div style={$style}>
<p>{$text}</p>
</div>;
}
If a tag is misspelled or not closed, HHVM triggers a runtime error, which
may have gone unnoticed without XHP.
XHP enforces HTLM5 rules.
37. Introduction Server-side scripting Client-side scripting Thrift Databases
XHP
XHP prevents the cross-site scripting (XSS) vulnerability.
$user_name = $_REQUEST[’name’];
echo ’<html><head><title>Welcome</title></head>’;
echo ’<body>Welcome ’ . $user_name . ’</body></html>’;
If a user submits a string containing HTML markup, it will be interpreted
by the browser as part of the document object model (DOM). To avoid:
$user_name = htmlspecialchars($_REQUEST[’name’]);
Applying it exactly once is tough with large codebase, something XHP
automatically takes care of.
XHP dates back to 2009. Since 2015, 100% of FB’s web frontend code
uses XHP to generate HTML.
38. Introduction Server-side scripting Client-side scripting Thrift Databases
React
React is a JavaScript library for building user interfaces (UI) rendered
as HTML.
React only provides the“V”, the View layer, in the MVC template.
React was built at FB, was released in March 2013, open-sourced on
May 29, 2013.
39. Introduction Server-side scripting Client-side scripting Thrift Databases
React – Virtual DOM
The browser has its own Document Object Model (DOM). The key feature
of React is that it keeps an in-memory copy of the DOM, called the virtual
DOM.
The developer does not directly update the brower’s DOM to
add/modify/remove UI elements. Instead, the developer updates the
virtual DOM. React takes care of comparing the browser’s DOM and its
own virtual DOM, and updates the browser’s DOM as efficiently as
possible. If there are e.g. tabs on a page, React will only update the visible
tab, not the hidden ones.
Ember’s Glimmer engine is heavily inspired by React’s virtual DOM.
40. Introduction Server-side scripting Client-side scripting Thrift Databases
React – Create a simple element
<html><body>
<div id="app"></div>
<script src="https://fb.me/react-15.1.0.js"</script>
<script src="https://fb.me/react-dom-15.1.0.js"</script>
<script>
var title = React.createElement("h1",
{id:"titleId", className:"titleClass"}, "Hello World!");
ReactDOM.render(title, document.getElementById("app"));
</script>
</body></html>
which outputs
<div id="app">
<h1 id="titleId" class="titleClass">Hello World!</h1>
</div>
41. Introduction Server-side scripting Client-side scripting Thrift Databases
React – Create an element with children
A tag content may also be some children tags:
var obj = React.createElement("ul", null,
React.createElement("li", null, "1 lb Salmon"),
React.createElement("li", null, "1 cup Pine Nuts"),
React.createElement("li", null, "2 cups Butter Lettuce")
);
ReactDOM.render(obj, document.getElementById("app"));
which outputs
<div id="app">
<ul>
<li>1 lb Salmon</li><li>1 cup Pine Nuts</li>
<li>2 cups Butter Lettuce</li>
</ul>
</div>
42. Introduction Server-side scripting Client-side scripting Thrift Databases
React – Create elements with map
A li element can be created for each element in an array, with map:
var items = ["1 lb Salmon", "1 cup Pine Nuts",
"2 cups Butter Lettuce"];
var obj = React.createElement("ul", null,
items.map((ingredient, i) =>
React.createElement("li", { key: i }, ingredient)
)
);
ReactDOM.render(obj, document.getElementById("app"));
However, we need to write the specific array name (items). We would like
to receive the array as an input parameter.
44. Introduction Server-side scripting Client-side scripting Thrift Databases
React – JSX
JSX for React is what XHP is for PHP/Hack:
const Ingredients = ({ name, list }) =>
<h1>{name}</h1>
<ul className="ingredients">
{list.map((ingredient, i) =>
<li key={i}>{ingredient}</li>
)}
</ul>;
var ingredients = ["1 lb Salmon", "1 cup Pine Nuts",
"2 cups Butter Lettuce"];
ReactDOM.render(
<Ingredients name="Delicious recipe" list={ingredients} />,
document.getElementById("app"));
45. Introduction Server-side scripting Client-side scripting Thrift Databases
Flux
Flux is FB’s application architecture pattern for building user interfaces.
Example : input text area and button to add items to a todo list.
1 The View receives a click event.
2 The View uses the Dispatcher to broadcast the message (called an
action)“one wants to add an item to the todo list”.
3 The Store keeps the data, namely all the todo list items (as an array).
4 On startup, the Store told the Dispatcher that it wanted to be
informed about dispatched actions.
5 The Store handles the received action and adds the new item to its
array.
6 The Store tells the View to refresh, based on the Store’s data.
53. Introduction Server-side scripting Client-side scripting Thrift Databases
Flux – Notes
There is only one Dispatcher in the application.
There may be multiple Stores and multiple Views.
The Views completely re-render upon change in the Stores’ data.
The re-rendering is on React’s virtual DOM, then React makes sure
to update the browser’s DOM very efficiently.
Flux is only a pattern, implemented in many frameworks, including
FB’s Flux, Reflux, Redux, Alt.
FB also developed and open sourced Flow, a static type checker for
JavaScript.
54. Introduction Server-side scripting Client-side scripting Thrift Databases
GraphQL
const FriendList = ({ friends }) =>
<div id="div_friend_list">
{friends.map(f => <Friend friend={f} />)}
</div>;
const Friend = ({ friend }) =>
<div id="div_friend">
<FriendImg urlImg={friend.urlImg} />
<span>{friend.name}</span>
<span>Mutual friends: {friend.numMutualFriends}</span>
</div>;
const FriendImg = ({ urlImg }) => <img src={urlImg} />;
What if we want to add an icon on each friend’s image to tell which
friends are verified users?
55. Introduction Server-side scripting Client-side scripting Thrift Databases
GraphQL
Each React component can be accompanied by a short GraphQL code
listing its data dependencies, independently of the other React
components.
Each React component could use e.g. Ajax to request its data to the
server. However, this would imply too many server round-trips.
56. Introduction Server-side scripting Client-side scripting Thrift Databases
Relay
Relay aggregates all the required data dependencies to reduce the number
of queries to the server.
Relay is an evolution of Flux. For instance, Relay uses only one Store.
Some FB projects use React/Flux, whereas some others use
React/Relay/GraphQL.
57. Introduction Server-side scripting Client-side scripting Thrift Databases
React Native
In March 2015 FB open sourced React Native, a framework for building
cross-platform applications which render natively on iOS and Android.
Netflix modified React to render on many televisions and DVD players.
Views in React Native are also written in JavaScript/HTML/CSS.
On April 18, 2017 FB announced React Fiber and Relay Modern.
58. Introduction Server-side scripting Client-side scripting Thrift Databases
Thrift
FB developed and open sourced Thrift, which is meant to build
cross-platform RPC services that can connect applications written in
different languages, over a network.
59. Introduction Server-side scripting Client-side scripting Thrift Databases
Databases
Cassandra (open sourced in 2008) is a NoSQL database designed to
handle large amounts of data across many servers, initially to power
FB’s Inbox Search. FB abandoned Cassandra in late 2010 for HBase.
Cassandra is still used by Apple, AppScale, Digg, Netflix, Reddit. . .
RocksDB is an embedded database, optimized to exploit many CPUs
and use efficiently SSDs. RocksDB is used by FB, Yahoo!, LinkedIn.
MyRocks is a RocksDB storage engine for MySQL.
FB developed and open sourced Hive and Presto which are SQL query
engines for analytics at scale. In 2013 FB gave up Hive/MapReduce
for Presto, to perform interactive queries against their 300PB data
warehouse.