phpscript, a PHP application server written in Go
phpscript serves an application directory. Each endpoint is a PHP file whose annotation is its route, migrations run before it listens, and every request is traced. One static binary, no PHP on the host.
Features
- File-based routing with path parameters
- SQL migrations applied at startup
- SQLite, MySQL and Postgres bindings
- A compiling template engine
- Composer packages
- Request tracing at /debug/oida
Laravel, Symfony and WordPress won't run on it, and it implements part of the PHP standard library.
How do you build an application?
Install the binary, write an endpoint, point the server at the folder. There is no scaffolding step and no front controller to wire up.
-
Install
One Go install, or the published image. The binary is static, built with cgo disabled.
go install github.com/titpetric/phpscript@latest -
Write an endpoint
The annotation at the top of the file is the route. Path parameters arrive in $_PATH.
<?php // @route GET /bookmarks/{id} include "bootstrap.php"; $bookmark = $db->get("SELECT title, url FROM bookmarks WHERE id = ?", (int)$_PATH["id"]); $tpl->load("show.tpl"); $tpl->assign(array("bookmark" => $bookmark)); $tpl->render(); -
Serve the directory
The server applies migrations, scans annotations, then listens. Check what it registered with list.
phpscript server . phpscript list ./...
phpscript at the terminal
phpscript FAQ
Can phpscript run Laravel, Symfony or WordPress?
No. phpscript is its own application framework: you write endpoints against it rather than porting an existing codebase onto it. It implements a subset of PHP syntax and part of the standard library, so most existing projects will not run unchanged.
Is phpscript a server or a library?
Both, but mostly a server. phpscript server serves an application directory, applying migrations and registering routes before it listens. It also embeds in a Go program, which is how you give PHP typed Go functions to call.
How does routing work?
Each endpoint is a PHP file with an annotation naming its method and path, so the file tree is the routing table and there is no front controller. Path parameters are declared in braces and arrive in $_PATH. Run phpscript list to see every route the server will register.
Does it handle databases and migrations?
Yes. Connections are named in the configuration, queries bind their parameters, and migrations are plain .up.sql files applied by a startup file that runs to completion before the server accepts a request. sqlite, mysql and postgres are supported.
Can I use Composer packages?
Yes. Require them in composer.json and include vendor/autoload.php the way you normally would. The route scanner skips vendor/, so a dependency cannot publish routes into your application.
How do I see what a request did?
Tracing is built in and on by default. Every request becomes a trace and the work inside it becomes spans, including includes, PHP calls, template rendering and database queries, served at /debug/oida. Retention, sampling and the mount path are configurable.
How do I test an application?
Endpoints are HTTP, so test them over HTTP: the bundled demos ship venom suites that run in CI. Behaviour that does not need a server belongs in a .phpt fixture, which phpscript test runs for you.
Do I need cgo, or PHP installed?
Neither. phpscript is written in Go and builds with cgo disabled, so it cross-compiles and ships as a single static binary. There is no libphp to link and nothing to install on the host.
Need PHP inside a Go service?
We build that, along with web apps, dashboards and fast websites. Tell us in a sentence what it should do.