aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-rpc/php/worker.php
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-01 01:33:38 +0900
committernsfisis <nsfisis@gmail.com>2026-07-01 01:33:40 +0900
commit1de6ba5c6735e42b5f462c0b7489bcf172ccdc08 (patch)
tree3a26a8cfe640d10c0d028f0c5087b89e4c8eb167 /crates/shirabe-php-rpc/php/worker.php
parent2b1c6c58a8c9e9afa8ba54214bc0bee48b06142f (diff)
downloadphp-shirabe-1de6ba5c6735e42b5f462c0b7489bcf172ccdc08.tar.gz
php-shirabe-1de6ba5c6735e42b5f462c0b7489bcf172ccdc08.tar.zst
php-shirabe-1de6ba5c6735e42b5f462c0b7489bcf172ccdc08.zip
feat(php-rpc): query real PHP version and binary for --version
Add a minimal shirabe-php-rpc crate that spawns the system PHP as a child process and asks it for runtime information over a Unix domain socket, then use it to fill the `--version` PHP line with the real \PHP_VERSION and \PHP_BINARY instead of fixed placeholder values. See docs/dev/php-rpc.md for the design and scope. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-rpc/php/worker.php')
-rw-r--r--crates/shirabe-php-rpc/php/worker.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/crates/shirabe-php-rpc/php/worker.php b/crates/shirabe-php-rpc/php/worker.php
new file mode 100644
index 0000000..214817a
--- /dev/null
+++ b/crates/shirabe-php-rpc/php/worker.php
@@ -0,0 +1,37 @@
+<?php
+
+// PHP glue worker. See docs/dev/php-rpc.md.
+
+$client = @stream_socket_client('unix://' . $argv[1], $errno, $errstr);
+if ($client === false) {
+ exit(1);
+}
+$dispatch = [
+ 'get_php_version' => static fn() => PHP_VERSION,
+ 'get_php_binary' => static fn() => PHP_BINARY,
+];
+$read_exact = static function ($conn, int $len): ?string {
+ $buf = '';
+ while (strlen($buf) < $len) {
+ $chunk = fread($conn, $len - strlen($buf));
+ if ($chunk === false || $chunk === '') {
+ return null;
+ }
+ $buf .= $chunk;
+ }
+ return $buf;
+};
+while (true) {
+ $header = $read_exact($client, 8);
+ if ($header === null) {
+ break;
+ }
+ $len = unpack('P', $header)[1];
+ $name = $len === 0 ? '' : $read_exact($client, $len);
+ if ($name === null) {
+ break;
+ }
+ $result = isset($dispatch[$name]) ? ($dispatch[$name])() : null;
+ $payload = serialize($result);
+ fwrite($client, pack('P', strlen($payload)) . $payload);
+}