Deploying PHP 7
Deploying PHP 7 CTO Crunch Paris Jan.14, 2016 http://talks.php.net/ctocrunch Rasmus Lerdorf @rasmus 1993 #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define ishex(x) (((x) >= '0' && (x) <= '9') || ((x) >= 'a' && \ (x) <= 'f') || ((x) >= 'A' && (x) <= 'F')) int htoi(char *s) { int value; char c; c = s[0]; if(isupper(c)) c = tolower(c); value=(c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16; c = s[1]; if(isupper(c)) c = tolower(c); value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10; return(value); } void main(int argc, char *argv[]) { char *params, *data, *dest, *s, *tmp; char *name, *age; puts("Content-type: text/html\r\n"); puts("<HTML><HEAD><TITLE>Form Example</TITLE></HEAD>"); puts("<BODY><H1>My Example Form</H1>"); puts("<FORM action=\"form.cgi\" method=\"GET\">"); puts("Name: <INPUT type=\"text\" name=\"name\">"); puts("Age: <INPUT type=\"text\" name=\"age\">"); puts("<BR><INPUT type=\"submit\">"); puts("</FORM>"); data = getenv("QUERY_STRING"); if(data && *data) { params = data; dest = data; while(*data) { if(*data=='+') *dest=' '; else if(*data == '%' && ishex(*(data+1))&&ishex(*(data+2))) { *dest = (char) htoi(data + 1); data+=2; } else *dest = *data; data++; dest++; } *dest = '\0'; s = strtok(params,"&"); do { tmp = strchr(s,'='); if(tmp) { *tmp = '\0'; if(!strcmp(s,"name")) name = tmp+1; else if(!strcmp(s,"age")) age = tmp+1; } } while(s=strtok(NULL,"&")); printf("Hi %s, you are %s years old\n",name,age); } puts("</BODY></HTML>"); } 1993 use CGI qw(:standard); print header; print start_html('Form Example'), h1('My Example Form'), start_form, "Name: ", textfield('name'), p, "Age: ", textfield('age'), p, submit, end_form; if(param()) { print "Hi ",em(param('name')), "You are ",em(param('age')), " years old"; } print end_html; 1994 <html><head><title>Form Example</title></head> <body><h1>My Example Form</h1> <form action="form.phtml" method="POST"> Name: <input type="text" name="name"> Age: <input type="text" name="age"> <br><input type="submit"> </form> <?if($name):?> Hi <?echo $name?>, you are <?echo $age?> years old <?endif?> </body></html> ✔ engine improvements 100%+ performance gain on most real-world applications Lower memory usage, sometimes drastically lower ✔ Persistent secondary file-based cache for OPCache ; --enable-opcache-file ; php.ini opcache.file_cache=/var/tmp ; php-cli.ini opcache.enable_cli=1 opcache.file_cache=/var/tmp opcache.file_cache_only=1 $ time composer >/dev/null real 0m0.040s user 0m0.032s sys 0m0.004s $ time composer >/dev/null real 0m0.019s user 0m0.016s sys 0m0.000s $ time php -d opcache.enable=0 /usr/local/bin/composer >/dev/null real 0m0.033s user 0m0.032s sys 0m0.000s /var/tmp ├── 7eeb6fe88104116c27c5650ddd83abf0 │ └── usr │ └── local │ └── bin │ └── composer.bin └── 7eeb6fe88104116c27c5650ddd83abf0phar: └── usr └── local └── bin └── composer ├── bin │ └── composer.bin ├── src │ ├── bootstrap.php.bin │ └── Composer │ ├── Command │ │ ├── AboutCommand.php.bin │ │ ├── ArchiveCommand.php.bin │ │ ├── ClearCacheCommand.php.bin │ │ ├── Command.php.bin │ │ ├── ConfigCommand.php.bin │ │ ├── CreateProjectCommand.php.bin │ │ ├── DependsCommand.php.bin │ │ ├── DiagnoseCommand.php.bin │ │ ├── DumpAutoloadCommand.php.bin │ │ ├── GlobalCommand.php.bin │ │ ├── Helper │ │ │ └── DialogHelper.php.bin │ │ ├── HomeCommand.php.bin │ │ ├── InitCommand.php.bin │ │ ├── InstallCommand.php.bin │ │ ├── LicensesCommand.php.bin │ │ ├── RemoveCommand.php.bin │ │ ├── RequireCommand.php.bin │ │ ├── RunScriptCommand.php.bin │ │ ├── SearchCommand.php.bin │ │ ├── SelfUpdateCommand.php.bin │ │ ├── ShowCommand.php.bin │ │ ├── StatusCommand.php.bin │ │ ├── UpdateCommand.php.bin │ │ └── ValidateCommand.php.bin │ ├── Composer.php.bin │ ├── Console │ │ └── Application.php.bin │ ├── Factory.php.bin │ ├── IO │ │ ├── BaseIO.php.bin │ │ ├── ConsoleIO.php.bin │ │ └── IOInterface.php.bin │ ├── Package │ │ ├── BasePackage.php.bin │ │ └── PackageInterface.php.bin │ ├── Script │ │ └── ScriptEvents.php.bin │ └── Util │ └── ErrorHandler.php.bin └── vendor ├── autoload.php.bin ├── composer │ ├── autoload_classmap.php.bin │ ├── autoload_namespaces.php.bin │ ├── autoload_psr4.php.bin │ ├── autoload_real.php.bin │ └── ClassLoader.php.bin └── symfony └── console └── Symfony └── Component └── Console ├── Application.php.bin ├── Command │ ├── Command.php.bin │ ├── HelpCommand.php.bin │ └── ListCommand.php.bin ├── Descriptor │ ├── ApplicationDescription.php.bin │ ├── DescriptorInterface.php.bin │ ├── Descriptor.php.bin │ ├── JsonDescriptor.php.bin │ ├── MarkdownDescriptor.php.bin │ ├── TextDescriptor.php.bin │ └── XmlDescriptor.php.bin ├── Formatter │ ├── OutputFormatterInterface.php.bin │ ├── OutputFormatter.php.bin │ ├── OutputFormatterStyleInterface.php.bin │ ├── OutputFormatterStyle.php.bin │ └── OutputFormatterStyleStack.php.bin ├── Helper │ ├── DebugFormatterHelper.php.bin │ ├── DescriptorHelper.php.bin │ ├── DialogHelper.php.bin │ ├── FormatterHelper.php.bin │ ├── HelperInterface.php.bin │ ├── Helper.php.bin │ ├── HelperSet.php.bin │ ├── InputAwareHelper.php.bin │ ├── ProcessHelper.php.bin │ ├── ProgressHelper.php.bin │ ├── QuestionHelper.php.bin │ ├── TableHelper.php.bin │ ├── Table.php.bin │ └── TableStyle.php.bin ├── Input │ ├── ArgvInput.php.bin │ ├── ArrayInput.php.bin │ ├── InputArgument.php.bin │ ├── InputAwareInterface.php.bin │ ├── InputDefinition.php.bin │ ├── InputInterface.php.bin │ ├── InputOption.php.bin │ └── Input.php.bin └── Output ├── ConsoleOutputInterface.php.bin ├── ConsoleOutput.php.bin ├── NullOutput.php.bin ├── OutputInterface.php.bin ├── Output.php.bin └── StreamOutput.php.bin 32 directories, 87 files ✔ Abstract Syntax Tree!! echo substr("abc", [1,2]); % phan -a test.php AST_STMT_LIST @ 1 0: AST_STMT_LIST @ 2 0: AST_ECHO @ 2 0: AST_CALL @ 2 0: AST_NAME @ 2 flags: NAME_NOT_FQ (1) 0: "substr" 1: AST_ARG_LIST @ 2 0: "abc" 1: AST_ARRAY @ 2 0: AST_ARRAY_ELEM @ 2 flags: 0 0: 1 1: null 1: AST_ARRAY_ELEM @ 2 flags: 0 0: 2 1: null % phan test.php test.php:2 TypeError arg#2(start) is int[] but substr() takes int ✔ Exceptions on Fatals function call_method($obj) { $obj->method(); } call_method(null); Fatal error: Uncaught Error: Call to a member function method() on null in file:2 Stack trace: #0 file(4): call_method(NULL) #1 {main} thrown in file on line 2 try { call_method(null); } catch (Error $e) { echo "Caught Exception: {$e->getMessage()}\n"; } Caught Exception: Call to a member function method() on null PHP 7 Exception Hierarchy Throwable ➥ Exception implements Throwable ➥ Error implements Throwable ➥ TypeError extends Error ➥ ParseError extends Error ✔ Return Types function get_config(): array { return 42; } get_config(); Fatal error: Uncaught TypeError: Return value of get_config() must be of the type array, integer returned in file:2 Stack trace: #0 file(4): get_config() #1 {main} thrown in file on line 2 ✔ Coercive Scalar Types function logmsg(string $msg, int $level, float $severity) { var_dump($msg); // string(1) "1" var_dump($leve
The rest of this page is on the live site.