codemotion madrid 2013 - [php] desarrollo de extensiones en c c++
Post on 13-Dec-2014
420 Views
Preview:
DESCRIPTION
TRANSCRIPT
[PHP] Desarrollo de extensiones en c/c++CODEMOTION Madrid 2013
Un poquito de SPAM
Un poquito de SPAM
Daniel González@desarrolla2
Un poquito de SPAM
@phpmad
Objetivo
Objetivo
Introducción teóricaDesarrollo de extensiones en C/C++
¿Que es PHP?
“PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language”. -wikipedia
¿Que es una extensión?
“An extension in PHP is in fact a module providing some functionality to the PHP Engine.” - Shahar Evron
¿Para que extender PHP?
¿Para que extender PHP?
¿Para que extender PHP?
¿Por que no hacerlo?
¿Por que no hacerlo?
“spaPHPetti code”
¿Por que no hacerlo?
¿Por que no hacerlo?
¿Por que no hacerlo?
¿Por que no hacerlo?
strtoupper
PHP_FUNCTION(strtoupper){ char *arg; int arglen;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arglen) == FAILURE) { return; }
arg = estrndup(arg, arglen); php_strtoupper(arg, arglen); RETURN_STRINGL(arg, arglen, 0);}
strtoupper
PHPAPI char *php_strtoupper(char *s, size_t len){ unsigned char *c, *e;
c = (unsigned char *)s; e = (unsigned char *)c+len;
while (c < e) { *c = toupper(*c); c++; } return s;}
strtoupper
<?phpecho "Testing strtoupper: ";$test = "abCdEfg";$upper = strtoupper($test);if ($upper == "ABCDEFG") { echo("passed\n");} else { echo("failed!\n");}?>
strtoupper
--TEST--Test strtoupper on non-ASCII characters--SKIPIF--<?phpif (!setlocale(LC_CTYPE, "de_DE", "de", "german", "ge", "de_DE.ISO8859-1", "ISO8859-1")) { die("skip locale needed for this test is not supported on this platform");}?>--FILE--<?php$chars = "�";// Not sure which is most portable. BSD's answer to this one. A small array based on PHP_OS should// cover a majority of systems and makes the problem of locales transparent for the end user.setlocale(LC_CTYPE, "de_DE", "de", "german", "ge", "de_DE.ISO8859-1", "ISO8859-1");echo strtoupper($chars)."\n";?>--EXPECT--
¿Por que no hacerlo?
github.com/php/php-srcrepositorio git desde 1999140 committers50,000 commits ~ 10 committers / año
¿Por que no hacerlo?
github.com/symfony/symfonyrepositorio git desde 2010770 committers15,000 commits ~ 250 committers / año
¿Por que no hacerlo?
¿Que necesito?
código fuente de phpentorno de compilaciónconocimientos de c/c++conocimientos de php ( bajo el capó )
Bajo el capó
Zend Engine
Zend Extension APIZend API
PHP Core
Extensions
PHP API
SAPI
Application ( apache, cli, nginx, php-fpm )
PHP Architecture
Bajo el capó
PHP Startup
Module Initialization and configuration
Child
Exit
Fork Child
Exit
Fork
SAPI Startup
MINIT Signals
RINIT Signals
RSHUTDOWN
Engine Init
Sandboxing
Bajo el capó
PHP Code LEXER Expressions PARSER /COMPILER OP Code
Ejemplos prácticosDesarrollo de extensiones en C/C++
RelaxingCup();Desarrollo de extensiones en C/C++
PrimeNumbers->factorize(1000,10000);Desarrollo de extensiones en C/C++
afile_put_contents();Desarrollo de extensiones en C/C++
afile_put_contents
Exit
ChildRINIT
Signals
Module Initialization and configurationMINIT
Signals fopen
fwritefclose
RSHUTDOWN
Para terminar ...Desarrollo de extensiones en C/C++
Conclusiones
Referencias
https://wiki.php.net/internals/references
¿Preguntas?Desarrollo de extensiones en C/C++
¡Gracias!Desarrollo de extensiones en C/C++
top related