Taking PHP Seriously

Slack uses PHP for most of its server-side application logic, which is an unusual choice these days. Why did we choose to build a new project in this language? Should you? Most programmers who have only casually used PHP know two things about it: that it is a bad language, which they would never use if…

Keith Adams
12 min readadvanced
--
View Original

Overview

The article discusses Slack's decision to use PHP for server-side application logic, addressing common misconceptions about the language's reputation. It highlights PHP's strengths in web development, its unique environment, and the transition to Hack and HHVM for improved performance and safety.

What You'll Learn

1

How to leverage PHP's unique request-oriented environment for better application performance

2

Why PHP remains a viable choice for modern web applications despite its flaws

3

When to consider transitioning from PHP to Hack for type safety and performance

Prerequisites & Requirements

  • Basic understanding of web development concepts
  • Familiarity with PHP programming(optional)

Key Questions Answered

What are the main advantages of using PHP for web development?
PHP provides a unique request-oriented environment that allows for organic fault isolation, safe concurrency, and a fast programmer workflow. This results in reduced costs of bugs and higher developer productivity, making it a strong choice for web applications despite its flaws.
What are the common criticisms of PHP as a programming language?
Common criticisms of PHP include surprise type conversions, inconsistencies in reference and value semantics, and a failure-oblivious philosophy that can lead to undetected errors. These issues can complicate development and increase the likelihood of defects in applications.
How does Hack improve upon PHP's shortcomings?
Hack introduces a gradual typing system that allows developers to express verifiable data invariants while maintaining PHP's dynamic nature. This helps eliminate issues like surprise type conversions and improves overall code safety and maintainability.
What performance improvements can be expected from using HHVM?
HHVM offers significant performance enhancements, with reports of up to 11.6x improvement in CPU efficiency over the traditional PHP interpreter. This can lead to lower latency and better resource utilization for web applications.

Key Statistics & Figures

CPU efficiency improvement
11.6x
Reported by Facebook when comparing HHVM to the traditional PHP interpreter.
Latency improvement
Significant drops
Observed by Slack after migrating web environments to HHVM.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Backend
Php
Used for server-side application logic at Slack.
Backend
Hack
A gradual typing system developed to enhance PHP's capabilities.
Backend
Hhvm
A JIT environment for PHP that improves performance.

Key Actionable Insights

1
Consider PHP for new web projects if you prioritize rapid development and a strong ecosystem.
PHP's unique request-oriented environment can facilitate faster development cycles and better fault isolation, making it suitable for many web applications.
2
Evaluate transitioning to Hack if your PHP codebase is growing complex and requires more type safety.
Hack's gradual typing system allows for a smooth transition, enabling developers to enhance code quality without a complete rewrite.
3
Utilize HHVM to improve application performance and reduce server costs.
By migrating to HHVM, organizations can experience substantial performance gains, which can lead to lower operational costs and improved user experience.

Common Pitfalls

1
Developers often encounter issues with surprise type conversions in PHP, leading to unexpected behavior.
This occurs because PHP's type handling can lead to confusing comparisons, such as evaluating '123' == 123 as true, which can introduce subtle bugs in applications.
2
Inconsistencies in PHP's standard library can confuse developers, especially those familiar with other programming languages.
As PHP has evolved, its API design has shifted, leading to a mix of naming conventions and styles that can be jarring and complicate code readability.

Related Concepts

Gradual Typing In Programming Languages
Performance Optimization Techniques
Web Application Architecture Patterns