首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Symfony 2 CronJob

Symfony 2 CronJob
EN

Stack Overflow用户
提问于 2014-12-10 13:31:13
回答 1查看 606关注 0票数 0

你好,我在控制器中有一个函数:

代码语言:javascript
复制
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中做到这一点。

有人找到解决办法了吗?也许是个例子?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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和队列的好教程。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27402310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档