Last updated: August 26, 2026.
PHP runs on the server to produce HTML, JSON, files, command-line output, and background jobs. It also provides database, networking, image, XML, and cryptography APIs through core features and extensions.
Return a JSON response
<?php
declare(strict_types=1);
header('Content-Type: application/json; charset=UTF-8');
echo json_encode(
['status' => 'ok', 'time' => (new DateTimeImmutable())->format(DATE_ATOM)],
JSON_THROW_ON_ERROR
);Common uses
| Task | Typical PHP tools |
|---|---|
| Render websites | Templates, sessions, cookies, routing |
| Build APIs | JSON, HTTP headers, authentication, validation |
| Work with databases | PDO and database-specific drivers |
| Process files and data | Streams, CSV, XMLWriter, JSON |
| Run scheduled work | CLI scripts, queues, cron or task schedulers |
| Integrate services | cURL, sockets, vendor SDKs |
Use supported PHP releases, install only needed extensions, validate inputs, escape outputs, and keep credentials in protected configuration.