你好,我在控制器中有一个函数:
if (!function_exists("ssh2_connect"))
die("function ssh2_connect doesn't exist");
if (!($con = ssh2_connect("myipadresherenotshowingtoyouguys", 22))) {
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password secretpassword
if (!ssh2_auth_password($con, "blablabla", "blablabla!")) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "okay: logged in...\n";
// execute a command
$command = 'ssid "Wentzo test2" hide-ssid';
if (!($stream = ssh2_exec($con, $command))) {
echo "fail: unable to execute command\n";
} else {
$stream2 = ssh2_exec($con, $command_save);
// collect returning data from command
stream_set_blocking($stream, true);
$data = "";
while ($buf = fread($stream, 4096)) {
$data .= $buf;
}
fclose($stream);
}
}
}当按下submit按钮时,我想以cron作业的形式运行这个脚本。但我不知道如何在symfony 2中做到这一点。
有人找到解决办法了吗?也许是个例子?
发布于 2014-12-10 16:21:07
你要找的概念是排队。
我建议您使用类似Beanstalkd、RabbitMQ或任何其他排队系统来处理这个问题。
您的想法是将处理方法放入Symfony命令:http://symfony.com/doc/current/components/console/introduction.html#creating-a-basic-command
在该命令中,您将从队列中读取数据,并根据队列中的“作业”运行进程。
在您的控制器中,唯一要做的事情是将一个新作业推入该队列。作业将包含一些数据,您可以在命令中使用这些数据进行处理。
为了更好地理解这个概念,您可以浏览以下幻灯片:http://www.slideshare.net/cakper/2014-0821-symfony-uk-meetup-scaling-symfony2-apps-with-rabbit-mq
你可能想读更多关于排队的概念。
由于某些原因,我无法找到关于Symfony2和队列的好教程。
https://stackoverflow.com/questions/27402310
复制相似问题