本文整理匯總了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));
}