# 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. ## Install Save in your project root: ## Quick Use ```bash # 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 "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): ```bash curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer composer init composer require monolog/monolog ``` ## Intro 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). - **Repo**: https://github.com/php/php-src - **Stars**: 39K+ - **Language**: C - **License**: PHP License v3.01 ## What PHP Does - **Server-side scripting** — embedded in HTML or standalone - **CLI execution** — scripts, CLIs, cron jobs - **Built-in web server** — `php -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 ```bash # 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 - Docs: https://www.php.net/docs.php - GitHub: https://github.com/php/php-src - License: PHP License --- Source: https://tokrepo.com/en/workflows/7cce7f80-3606-11f1-9bc6-00163e2b0d79 Author: AI Open Source