Tuesday, February 16, 2010

HipHop for PHP: Move Fast php BINARIES

http://developers.facebook.com/news.php?blog=1&story=358


Hacking Up HipHop

One night at a Hackathon a few years ago (see Prime Time Hack), I started my first piece of code transforming PHP into C++. The languages are fairly similar syntactically and C++ drastically outperforms PHP when it comes to both CPU and memory usage. Even PHP itself is written in C. We knew that it was impossible to successfully rewrite an entire codebase of this size by hand, but wondered what would happen if we built a system to do it programmatically.

Finding new ways to improve PHP performance isn't a new concept. At run time the Zend Engine turns your PHP source into opcodes which are then run through the Zend Virtual Machine. Open source projects such as APC and eAccelerator cache this output and are used by the majority of PHP powered websites. There's also Zend Server, a commercial product which makes PHP faster via opcode optimization and caching. Instead, we were thinking about transforming PHP source directly into C++ which can then be turned into native machine code. Even compiling PHP isn't a new idea, open source projects like Roadsend and phc compile PHP to C, Quercus compiles PHP to Java, and Phalanger compiles PHP to .Net.

Needless to say, it took longer than that single Hackathon. Eight months later, I had enough code to demonstrate it is indeed possible to run faster with compiled code. We quickly added Iain Proctor and Minghui Yang to the team to speed up the pace of the project. We spent the next ten months finishing up all the coding and the following six months testing on production servers. We are proud to say that at this point, we are serving over 90% of our Web traffic using HipHop, all only six months after deployment.

2010 CWE/SANS Top 25 Most Dangerous Programming Errors

This is a brief listing of the Top 25 items, using the general ranking.

NOTE: 16 other weaknesses were considered for inclusion in the Top 25, but their general scores were not high enough. They are listed in the On the Cusp focus profile.

RankScoreIDName
[1]346CWE-79 Failure to Preserve Web Page Structure ('Cross-site Scripting')
[2]330CWE-89 Improper Sanitization of Special Elements used in an SQL Command ('SQL Injection')
[3]273CWE-120 Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
[4]261CWE-352 Cross-Site Request Forgery (CSRF)
[5]219CWE-285 Improper Access Control (Authorization)
[6]202CWE-807 Reliance on Untrusted Inputs in a Security Decision
[7]197CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
[8]194CWE-434 Unrestricted Upload of File with Dangerous Type
[9]188CWE-78 Improper Sanitization of Special Elements used in an OS Command ('OS Command Injection')
[10]188CWE-311 Missing Encryption of Sensitive Data
[11]176CWE-798 Use of Hard-coded Credentials
[12]158CWE-805 Buffer Access with Incorrect Length Value
[13]157CWE-98 Improper Control of Filename for Include/Require Statement in PHP Program ('PHP File Inclusion')
[14]156CWE-129 Improper Validation of Array Index
[15]155CWE-754 Improper Check for Unusual or Exceptional Conditions
[16]154CWE-209 Information Exposure Through an Error Message
[17]154CWE-190 Integer Overflow or Wraparound
[18]153CWE-131 Incorrect Calculation of Buffer Size
[19]147CWE-306 Missing Authentication for Critical Function
[20]146CWE-494 Download of Code Without Integrity Check
[21]145CWE-732 Incorrect Permission Assignment for Critical Resource
[22]145CWE-770 Allocation of Resources Without Limits or Throttling
[23]142CWE-601 URL Redirection to Untrusted Site ('Open Redirect')
[24]141CWE-327 Use of a Broken or Risky Cryptographic Algorithm
[25]138CWE-362 Race Condition


http://cwe.mitre.org/top25/