jadedaniel / background-job
简单的后台任务创建器
1.0.6
2021-03-11 05:58 UTC
Requires
- php: >=8.0
Requires (Dev)
- phpunit/phpunit: ^8
README
PHP类,以非常简单的方式执行后台任务。
使用了在 stackoverflow.com 上找到的答案
http://stackoverflow.com/a/45966/464549
此功能需要在Unix平台上才能工作
安装
composer require diversen/background-job
用法
cd background-job && php example.php
example.php
:
<?php include_once "bgJob.php"; // Only used if autoloader is not enabled use diversen\bgJob; $bg = new bgJob(); $command = "./example.sh"; $bg->execute($command, "output.txt", "pid.txt"); // View pid echo $bg->pid . "\n";
这将执行 example.sh
#!/bin/bash echo "Hi, I'm sleeping for 5 seconds..." date sleep 5 echo "all Done."