6 conférences
5 minutes par conférences
Source : greenit.fr
Source : https://mobiforge.com/research-analysis/the-web-is-doom
ecometer.org
https://addons.mozilla.org/fr/firefox/addon/carbonalyser/
techologie.net
fairness.coop
@podcastEcho
@richardhanna
- 🐘 Développeur PHP
- Antenne AFUP Paris
- 🏂 Wakeboard
- 🌱 Maintainer Jane
Permet de décrire et valider des documents JSON.
{
"$id": "https://example.com/geographical-location.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Longitude and Latitude Values",
"description": "A geographical coordinate.",
"required": [
"latitude",
"longitude"
],
"type": "object",
"properties": {
"latitude": {
"type": "number",
"minimum": -90,
"maximum": 90
},
"longitude": {
"type": "number",
"minimum": -180,
"maximum": 180
}
}
}
- Anciennement Swagger
- Utilisé pour décrire des API
openapi: "3.0.0"
paths:
/pets:
get:
operationId: listPets
parameters:
- name: limit
in: query
required: false
schema:
type: integer
format: int32
responses:
'200':
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Parfois l'API que l'on veut utiliser n'a pas de schéma disponible. On doit donc le créer à partir de zéro comme ici.
Souvent vous pourrez trouver un schéma pour les API que vous utilisez au quotidien :
- Slack slackapi/slack-api-specs
- Stripe stripe/openapi
openapi: 3.0.2
info:
version: 1.0.0
title: 'CatFacts API'
servers:
- url: https://cat-fact.herokuapp.com
paths:
/facts/random:
get:
operationId: randomFact
responses:
200:
description: 'Get a random `Fact`'
content:
application/json:
schema:
$ref: '#/components/schemas/Fact'
components:
schemas:
Fact:
type: object
properties:
_id:
type: string
description: 'Unique ID for the `Fact`'
__v:
type: integer
description: 'Version number of the `Fact`'
user:
type: string
description: 'ID of the `User` who added the `Fact`'
text:
type: string
description: 'The `Fact` itself'
updatedAt:
type: string
format: date-time
description: 'Date in which `Fact` was last modified'
sendDate:
type: string
description: 'If the `Fact` is meant for one time use, this is the date that it is used'
deleted:
type: boolean
description: 'Weather or not the `Fact` has been deleted (Soft deletes are used)'
source:
type: string
description: 'Can be `user` or `api`, indicates who added the fact to the DB'
used:
type: boolean
description: 'Weather or not the `Fact` has been sent by the CatBot. This value is reset each time every `Fact` is used'
type:
type: string
description: 'Type of animal the `Fact` describes (e.g. ‘cat’, ‘dog’, ‘horse’)'
Une fois son schéma OpenApi trouvé, nous devons configurer Jane !
Il a besoin de plusieurs choses :
#!/usr/bin/env php
# .jane-openapi
<?php
return [
'openapi-file' => __DIR__ . '/schema.yaml',
'namespace' => 'CatFacts\Api',
'directory' => __DIR__ . '/generated/',
];
- Où est votre schéma ?
- Quel namespace appliquer aux classes générées ?
- Le dossier où mettre ses classes générées ?
$ rm -r generated/* && vendor/bin/jane-openapi generate
$ tree generated/
generated/
├── Client.php
├── Endpoint
│ └── RandomFact.php
├── Model
│ └── Fact.php
└── Normalizer
├── FactNormalizer.php
└── NormalizerFactory.php
3 directories, 5 files
<?php
require_once './vendor/autoload.php';
use CatFacts\Api\Client;
// on crée un client
$client = Client::create();
// on appelle un endpoint
$fact = $client->randomFact();
dump($fact);
Une fois que vous avez fait votre client API, rendez-le OpenSource !
Parce que si vous en avez eu besoin, d'autres en auront besoin aussi 😉
@nekdev
@nek-
Maxime Veber
// script.php
require_once "Product.php";
require_once "Card.php";
$card = new Card();
$product = new Product($card);
$card->addProduct($product);
$clone = clone $card;
$ php script.php
segmentation fault
$ apt install php7.3-cli-dbgsym
Toutes les infos sur le wiki
https://github.com/oerdnj/deb.sury.org/wiki/Debugging-Symbols
Ajouter l'option `--enable-debug`
$ ./buildconf
$ ./configure --enable-debug
$ make
./configure \
--build="$gnuArch" \
--with-config-file-path="$PHP_INI_DIR" \
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
--disable-cgi \
--enable-ftp \
--enable-mbstring \
--enable-mysqlnd \
--with-curl \
--with-libedit \
--with-openssl \
--with-zlib \
\
--enable-debug \ # <----- On a simplement rajouté ceci !
\
--with-pcre-regex=/usr \
--with-libdir="lib/$debMultiarch" \
$PHP_EXTRA_CONFIGURE_ARGS \
# ...
# ...
&& make install \
# && { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \
&& make clean \
$ gdb -ex=r --args php script.php
Reading symbols from ./php-src/sapi/cli/php...done.
Starting program: /home/nek/Dev/Web/PHP/Tests/segfault/php-src/sapi/cli/php script.php
Program received signal SIGSEGV, Segmentation fault.
0x00005555559342b3 in execute_ex (ex=0x7ffff2079560)
at /home/nek/Dev/Web/PHP/Tests/segfault/php-src/Zend/zend_vm_execute.h:50123
Télécharger
https://raw.githubusercontent.com/php/php-src/master/.gdbinit
(gdb) source ~/.gdbinit
(gdb) zbacktrace
# a lot of output
[0x7ffff2078e90] ClonableObject->cloneArray(reference) /ClonableObject.php:23
[0x7ffff2078d80] ClonableObject->__clone() /ClonableObject.php:12
[0x7fffff7ff860] ???
[0x7ffff2078c90] ClonableObject->cloneArray(object[0x7ffff2078ce0]) /ClonableObject.php:27
[0x7ffff2078b80] ClonableObject->__clone() /ClonableObject.php:12
<?php
abstract class ClonableObject
{
public function __clone ()
{
$properties = $this->getProperties();
foreach ($properties as $name) {
$value = $this->{$name};
if (is_object($value) || is_array($value)) {
$this->{$name} = $this->cloneArray($value);
}
}
}
abstract protected function getProperties();
private function cloneArray($data)
{
if (is_array($data) && is_object(reset($data)) || is_array($data)) {
foreach ($data as $item) {
return $this->cloneArray($item);
}
}
if (is_object($data)) {
return clone $data;
}
return $data;
}
}
# core file size (blocks)
$ ulimit -c
0
# Emplacement du core dump
$ cat /proc/sys/kernel/core_pattern
|/usr/share/apport/apport %p %s %c %d %P
$ ulimit -c unlimited
$ sudo echo "/tmp/core-%t-%p" | sudo tee /proc/sys/kernel/core_pattern
$ docker run -it --rm --ulimit core=-1 ubuntu:19.04 sh -c 'ulimit -a | grep core'
coredump(blocks) unlimited
services:
php-dbg:
build: docker/php-fpm-dbg
ulimits:
core: -1
$ docker run -it --privileged alpine sh
# echo "/tmp/core-%t-%p" > /proc/sys/kernel/core_pattern
Modifier la valeur du core pattern pour tous les dockers
ou avec docker-compose
; /etc/php/7.3/fpm/php-fpm.conf
; Set max core size rlimit for the master process.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
rlimit_core = unlimited
# Fichier /var/log/php7.3-fpm.log
[03-Oct-2019 17:44:30] WARNING: [pool www] child 27719 exited on signal 11
(SIGSEGV - core dumped) after 5.293810 seconds from start
[03-Oct-2019 17:44:30] NOTICE: [pool www] child 27723 started
$ gdb /usr/sbin/php-fpm7.0 /tmp/core-1512323070-27719
Puis utiliser les commandes gdb vues précédemment
Retrouvez un article détaillé à ce sujet sur le blog de Biig°
ou plutôt...
Crédit son : Team Wild
hook.js