PHP code example of corzcode / yii2-swoole-crontab
1. Go to this page and download the library: Download corzcode/yii2-swoole-crontab library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace console\controllers;
use yii\console\Controller;
use Yii;
class TestController extends Controller
{
//$num is process num $id is process id
public function actionIndex($id = 0, $num = 1)
{}
public function actionDo($id = 0, $num = 1)
{}
}
sh
#!/bin/sh
PHPBIN=/path/to/php
PHPCLICONF=/path/to/php.ini
script_dir=$( cd $(dirname $0); pwd)
pidpath="$script_dir/console/runtime"
helptxt="Usage: $0 cron {start|stop|reload|restart}"
pidfile="$pidpath/$1.pid"
cd $script_dir
cmd="yii cron/start"
case "$2" in
start)
echo "Starting CLI $1 server "
$PHPBIN -c $PHPCLICONF $cmd --pidfile=${pidfile}
;;
stop)
PID=`cat "${pidfile}"`
echo "Stopping CLI $1 server"
if [ ! -z "$PID" ]; then
kill -15 $PID
(( $? == 0 )) && echo -n '' > ${pidfile}
[ "$1" == "mq" ] && sleep 5
fi
;;
reload)
echo "Reload CLI $1 server"
PID=`cat "${pidfile}"`
if [ ! -z "$PID" ]; then
kill -10 $PID
fi
;;
restart)
$0 $1 stop
$0 $1 start
;;
*)
echo $helptxt
exit 1
esac
exit 0
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.