Configs2026年4月12日·1 分钟阅读

PHP — The Web Scripting Language Powering Much of the Internet

PHP is a popular general-purpose scripting language that is especially suited to web development. Fast, flexible, and pragmatic, PHP powers WordPress, Wikipedia, Facebook, Slack, and countless web applications worldwide.

AI
AI Open Source · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

# Install
brew install php                           # macOS
sudo apt install php                       # Debian/Ubuntu
docker run --rm -it php:8.3 bash           # Docker

php --version
php -S localhost:8000                       # Built-in dev server

Hello world:

<?php
// index.php
declare(strict_types=1);

function greet(string $name): string {
    return "Hello, " . $name;
}

$users = [
    ["name" => "Alice", "score" => 95],
    ["name" => "Bob",   "score" => 87],
];

usort($users, fn($a, $b) => $b["score"] <=> $a["score"]);

foreach ($users as $user) {
    printf("%s: %d\n", $user["name"], $user["score"]);
}

Composer (package manager):

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
composer init
composer require monolog/monolog
介绍

PHP (originally Personal Home Page, later PHP: Hypertext Preprocessor) is a popular general-purpose scripting language especially suited to web development. Created by Rasmus Lerdorf in 1994. Despite endless declarations of its death, PHP 8.x powers a huge portion of the web: WordPress (40%+ of all websites), Wikipedia, Facebook (Hack/HHVM fork), Slack, Shopify, Mailchimp. Modern PHP is fast (JIT in 8.0+), typed (union types, readonly, enums), and has a mature framework ecosystem (Laravel, Symfony).

What PHP Does

  • Server-side scripting — embedded in HTML or standalone
  • CLI execution — scripts, CLIs, cron jobs
  • Built-in web serverphp -S for dev
  • Huge standard library — strings, arrays, HTTP, crypto, DB, JSON
  • Frameworks — Laravel, Symfony, CodeIgniter, Phalcon, Yii
  • CMS — WordPress, Drupal, Joomla, Magento
  • ORM — Eloquent (Laravel), Doctrine (Symfony)
  • Composer — Packagist is the largest PHP package registry
  • JIT compiler — OPcache + JIT in PHP 8.0+
  • Modern syntax — union types, enums, readonly, attributes, first-class callable

Architecture

Zend Engine interprets PHP bytecode. OPcache caches compiled bytecode between requests. PHP-FPM process manager serves requests behind Nginx or Apache. PHP 8 added a JIT tracing optimizer on top of OPcache for CPU-bound workloads.

Self-Hosting

# Production stack
# PHP-FPM + Nginx
apt install php8.3-fpm nginx
systemctl enable php8.3-fpm nginx

Key Features

  • Embedded in HTML or standalone
  • JIT compiler (8.0+)
  • Union and intersection types
  • Enums (8.1+)
  • Readonly properties (8.1+) and readonly classes (8.2+)
  • Attributes (metadata annotations)
  • First-class callable syntax
  • Composer package ecosystem
  • Laravel and Symfony frameworks
  • WordPress and many CMS

Comparison

Language Use Startup Ecosystem
PHP Web, CLI Per-request Huge (CMS)
Python Web, ML, scripts Per-request (uvicorn) Huge
Ruby Web, scripts Per-request (Rails) Large
Node.js Web, CLI Long-running Huge
Go Services Long-running Large

常见问题 FAQ

Q: PHP 过时了吗? A: 没有。现代 PHP (8.x) 类型系统、性能、工具都和其他主流语言接近。WordPress 之类的 CMS 还是 PHP 主导。Laravel 生态非常健康。

Q: PHP vs Python web? A: PHP 在共享主机和 CMS 场景无可替代;Python 在 ML/数据 场景优势明显。Web 框架层面两者都很成熟(Laravel vs Django/FastAPI)。

Q: JIT 有多快? A: CPU-bound 提升明显(2-3x),web IO-bound 提升不大(因为每次请求重新编译一遍 bytecode)。OPcache 才是 web 性能的关键。

来源与致谢 Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产