【问题标题】:How to run a Symfony command from Heroku's Scheduler如何从 Heroku 的调度程序运行 Symfony 命令
【发布时间】:2015-09-10 13:22:53
【问题描述】:

我已经将 Heroku 的调度程序配置为运行 Symfony 2 命令:

bash app/console myapp:send:confirmations --verbose

并将其设置为每 10 分钟运行一次。

但是,在日志中我看到了这些消息:

2015-09-10T13:01:25.313711+00:00 heroku[api]: Starting process with command `bash app/console myapp:send:confirmations` by scheduler@addons.heroku.com
2015-09-10T13:01:44.151426+00:00 heroku[scheduler.7629]: Starting process with command `bash app/console myapp:send:confirmations --verbose`
2015-09-10T13:01:44.811500+00:00 heroku[scheduler.7629]: State changed from starting to up
2015-09-10T13:01:45.565021+00:00 app[scheduler.7629]: app/console: line 2: ?php: No such file or directory
2015-09-10T13:01:45.565093+00:00 app[scheduler.7629]: app/console: line 19: unexpected EOF while looking for matching `''
2015-09-10T13:01:45.565096+00:00 app[scheduler.7629]: app/console: line 28: syntax error: unexpected end of file
2015-09-10T13:01:46.291606+00:00 heroku[scheduler.7629]: State changed from up to complete
2015-09-10T13:01:46.278800+00:00 heroku[scheduler.7629]: Process exited with status 2

这三个相关的东西让我感到困惑:

2015-09-10T13:01:45.565021+00:00 app[scheduler.7629]: app/console: line 2: ?php: No such file or directory
2015-09-10T13:01:45.565093+00:00 app[scheduler.7629]: app/console: line 19: unexpected EOF while looking for matching `''
2015-09-10T13:01:45.565096+00:00 app[scheduler.7629]: app/console: line 28: syntax error: unexpected end of file

我有点困惑:文件app/console 似乎不存在,但随后脚本遇到了意外的 EOF(但文件不存在 o.O),然后文件意外结束(这不是和之前的消息一样吗?

我做错了什么?

【问题讨论】:

    标签: symfony heroku scheduler symfony-console heroku-api


    【解决方案1】:

    使用php 而不是bash 来启动控制台:

    php app/console myapp:send:confirmations --verbose
    

    我在 Ubuntu 15.04 上有相同的行为(崩溃):

    $ bash app/console
    app/console: line 2: ?php: No such file or directory
    app/console: line 18: unexpected EOF while looking for matching `''
    app/console: line 23: syntax error: unexpected end of file
    $ php app/console -v
    Symfony version 2.7.4 - app/prod
    ...
    

    似乎app/console开头的shebang被忽略了,PHP解释器没有被调用:

    #!/usr/bin/env php
    <?php
    ....
    

    以下是Aaron Copley的解释:

    无法执行

    使用绝对或相对路径运行二进制文件

    因此,如果您将文件标记为可执行文件并使用相对路径启动脚本,则会调用 PHP 解释器:

    $ chmod +x app/console
    $ ./app/console -v
    Symfony version 2.7.4 - app/prod
    

    【讨论】:

      猜你喜欢
      • 2022-07-07
      • 2019-02-10
      • 2016-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 1970-01-01
      • 2022-08-10
      相关资源
      最近更新 更多