Skip to main content

Runnable examples

The examples directory contains complete PHP scripts you can run with an installed Asyncara launcher. Download the documentation repository, open its directory in a terminal, and start with:

asyncara examples/tasks.php

The task example prints {"a":"first","b":"second"}. Both Tasks start before either result is collected; the shorter wait can finish first without changing the result keys.

Choose an example​

FileWhat it demonstratesExpected result
tasks.phpConcurrent tasks and keyed resultsJSON with first/second values
shared-waiter.phpCancelling one waiter without cancelling its shared operationwaiter cancelled, then kept
queue.phpA bounded producer/consumer queue55
streams.phpContext values in a bounded streamdemo:0 through demo:4
sqlite.phpParameter binding, transactions and savepointsOne saved note
files.phpAtomic replacement and bounded reads90000 bytes
network.phpA local TCP request and replyPING
processes.php with jobs.phpParallel registered jobsTwo SHA-256 values

SQLite uses an in-memory database. The file example creates and removes a temporary file, and the TCP example binds a local ephemeral port. ProcessPool needs the complete runtime installation described in the process guide.

Run the server and HTTP client together​

In one terminal:

asyncara examples/server.php

In a second terminal:

asyncara examples/http.php

The client makes four requests to the local server. Each response includes an ID and delay_ms: 10; completion order may vary. Stop the server with Ctrl+C when finished.

For a different port, use matching settings in the two terminals:

# Server terminal
ASYNCARA_LISTEN=127.0.0.1:8081 asyncara examples/server.php
# Client terminal
ASYNCARA_DEMO_URL=http://127.0.0.1:8081 asyncara examples/http.php

Examples using example.net in other guides need your service URL, credentials and certificates. Keep those values in application configuration, not in a copied example committed with secrets.