mirror of
https://github.com/crazywhalecc/quick-shell.git
synced 2026-07-02 14:25:44 +08:00
add quick php server
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace QuickShell\Commands;
|
namespace QuickShell\Commands;
|
||||||
|
|
||||||
use QuickShell\Annotations\Command;
|
use QuickShell\Annotations\Command;
|
||||||
|
use QuickShell\Annotations\CommandOption;
|
||||||
|
|
||||||
class ExampleCommand
|
class ExampleCommand
|
||||||
{
|
{
|
||||||
@@ -17,4 +18,33 @@ class ExampleCommand
|
|||||||
{
|
{
|
||||||
return cmd("curl -s http://ip.zhamao.xin");
|
return cmd("curl -s http://ip.zhamao.xin");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Command('php_server', '在当前目录使用PHP启动一个服务器')]
|
||||||
|
#[CommandOption(option_name: 'port', description: '端口号', required: true)]
|
||||||
|
public function phpServer(array $params)
|
||||||
|
{
|
||||||
|
$cmd = <<<CMD
|
||||||
|
case \$(uname -s) in
|
||||||
|
Linux) mysys="linux" ;;
|
||||||
|
*)
|
||||||
|
echo "Only support Linux!"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
if [ ! -f "/tmp/.qs_php" ]; then
|
||||||
|
echo "sys: \$mysys"
|
||||||
|
link="https://dl.zhamao.xin/php-bin/down.php?php_ver=8.1&arch=\$(uname -m)"
|
||||||
|
echo "Downloading php from \$link"
|
||||||
|
curl \$link -o /tmp/php.tgz -L && \
|
||||||
|
cd /tmp && \
|
||||||
|
tar -xzvf php.tgz && \
|
||||||
|
rm php.tgz && \
|
||||||
|
mv php .qs_php && \
|
||||||
|
chmod +x .qs_php
|
||||||
|
fi
|
||||||
|
/tmp/.qs_php -S 0.0.0.0:{port}
|
||||||
|
CMD;
|
||||||
|
$cmd = str_replace('{port}', $params['port'] ?? '8080', $cmd);
|
||||||
|
return cmd($cmd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user