Closed saundefined closed 1 hour ago
I'm not sure what is "run phpmicro from PHP file"
If you want to use micro like cli (something_like_php_command_but_micro /path/to/some.php
), you may look at fakecmd.php
If you want to run another php process in micro'd php codes, you may use command argument with proc_open
caller.php:
<?php
function runAnother(string $another, ?string $stdin = null): array {
$self = micro_get_self_filename();
$proc = proc_open([
$self,
"runsub",
$another,
], [
0 => ["pipe", "r"],
1 => ["pipe", "w"],
2 => ["pipe", "w"],
], $pipes);
if ($stdin !== null) {
fwrite($pipes[0], $stdin);
}
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
pcntl_wait($status);
return [
'stdout' => $stdout,
'stderr' => $stderr,
'rc' => pcntl_wexitstatus($status),
];
}
// assume this is a argument parser
// you may use https://www.php.net/manual/en/function.getopt.php to implement this
if ($argv[1]??null === "runsub") {
require_once($argv[2]);
} else {
$ret = runAnother("callee.php");
var_dump($ret);
}
Hi,
Example:
Downloaded phpmicro 8.3.6:
So.. 8.3.6 is
phpmicro
PHP version, and 8.3.11 is local PHP version.Is any chance to run
phpmicro
from PHP file?