本文整理汇总了PHP中app\models\Task::receiver方法的典型用法代码示例。如果您正苦于以下问题:PHP Task::receiver方法的具体用法?PHP Task::receiver怎么用?PHP Task::receiver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Task
的用法示例。
在下文中一共展示了Task::receiver方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transmitter
public static function transmitter($from_device_id, $to_device_id, $action_id, $retry = 3, $delay = 3)
{
$modelSetting = Setting::find()->select('data')->where(['name' => 'path_script_task'])->one();
for ($try = 1; $try <= $retry; $try++) {
// sudo visudo
// add www-data ALL=(ALL) NOPASSWD: ALL
// to grant execute right python
$command = 'sudo ' . $modelSetting->data . ' --fr ' . $from_device_id . ' --to ' . $to_device_id . ' --ac ' . $action_id;
Yii::info('$command: ' . $command, 'task-transmitter');
exec(escapeshellcmd($command), $output, $return_var);
foreach ($output as $line) {
Yii::info('$line: ' . $line, 'task-transmitter');
}
Yii::info('$return_var: ' . $return_var, 'task-transmitter');
if (0 != $return_var) {
if ($try < $retry) {
Yii::info('!return_var, retry and delay', 'task-transmitter');
sleep($delay);
continue;
} else {
Yii::error('!return_var, failed exec', 'task-transmitter');
return 'err:failed exec';
}
}
$return = Task::sscanfOutput($output);
if (!$return) {
Yii::info('sscanfOutput, !return', 'task-transmitter');
if ($try < $retry) {
Yii::info('!return, retry and delay', 'task-transmitter');
sleep($delay);
continue;
} else {
Yii::error('!return, no output', 'task-transmitter');
return 'err:no output';
}
}
Yii::info('sscanfOutput, return', 'task-transmitter');
// from and to are exchanged
$from = 0;
$to = 0;
$action = 0;
$message = '';
list($from, $to, $action, $message) = $return;
if ($from == $from_device_id and $to == $to_device_id and $action == $action_id) {
Yii::info('$message: ' . $message, 'task-transmitter');
return $message;
} else {
Yii::info('transmitter function to receiver function', 'task-transmitter');
// there is output but not for this task-transmitter
Task::receiver($output);
$try--;
}
if ($try >= $retry) {
Yii::error('!retry, failed trying', 'task-transmitter');
return 'err:failed trying';
} else {
Yii::info('retry', 'task-transmitter');
sleep($delay);
}
}
Yii::error('end, failed return', 'task-transmitter');
return 'err:failed return';
}
示例2: actionIndex
/**
* This command echoes what you have entered as the message.
* @param string $message the message to be echoed.
*/
public function actionIndex($output)
{
Yii::info('ReceiverController', 'task-receiver');
return Task::receiver(array($output));
}