Configure a static directory

Publish a CSS file, verify its URL, and choose the right static directory mode for your build.

Publish one file

Shell
mkdir -p public/assets
printf 'body { color: navy; }\n' > public/assets/app.css

Choose one mode below. Save its profile as m4w.json, start the server and run the test in a second terminal. Stop the server before trying another mode.

manifest

List each published file in the manifest. Keep that build immutable while workers serve it. Deploy a new directory and manifest together, then restart.

Shell
printf '["app.css"]\n' > public/assets/.m4w-manifest.json
JSON
{
  "listen": { "port": 9000 },
  "static": {
    "directories": [
      {
        "path": "public/assets",
        "prefix": "/assets",
        "mode": "manifest"
      }
    ]
  }
}
Shell
php vendor/mini4work/webserver/examples/server.php m4w.json
Shell
curl -i http://127.0.0.1:9000/assets/app.css

Expect HTTP 200 with body { color: navy; } in the response. The server matches /assets, finds app.css in the manifest and serves the file without calling your handler.

precompressed

Include the original and its encoded copies, for example ["app.css", "app.css.gz"]. Visitors still request /assets/app.css. The server uses Accept-Encoding to choose an available representation. No PHP compression extension is required.

Shell
gzip -c public/assets/app.css > public/assets/app.css.gz
printf '["app.css", "app.css.gz"]\n' > public/assets/.m4w-manifest.json
JSON
{
  "listen": { "port": 9000 },
  "static": {
    "directories": [
      {
        "path": "public/assets",
        "prefix": "/assets",
        "mode": "precompressed"
      }
    ]
  }
}
Shell
php vendor/mini4work/webserver/examples/server.php m4w.json
Shell
curl -sSI -H 'Accept-Encoding: gzip' http://127.0.0.1:9000/assets/app.css

HTTP/1.1 200 · Content-Encoding: gzip

secure

The server looks up each file within the opened directory at request time. This mode requires enabled FFI on a supported system, including Linux 5.6+ with openat2 or macOS 13+ on supported architectures. Restart if you replace the directory itself.

JSON
{
  "listen": { "port": 9000 },
  "static": {
    "directories": [
      {
        "path": "public/assets",
        "prefix": "/assets",
        "mode": "secure"
      }
    ]
  }
}
Shell
php -d ffi.enable=true vendor/mini4work/webserver/examples/server.php m4w.json

Add a file while the server is running. It is available immediately without a manifest.

Shell
cp public/assets/app.css public/assets/theme.css
curl -i http://127.0.0.1:9000/assets/theme.css

HTTP/1.1 200 · body { color: navy; }

Serve static files