Heroku支持多种类型的dyno配置,允许我们为应用程序设置 web
和 worker
进程类型,例如:
web: vendor/bin/heroku-php-apache2 web/
worker: php worker/myworker.php
web
dyno将处理网络流量,同时可以使用 worker
dyno类型as a background job (e.g.: to process a queue.)
文档没有向我说清楚 how these workers function, i.e.: how do they start? behave?
特别是:
-
Are they run just once at deployment? Or are they run repeatedly (if so when)?
-
Do they have a maximum execution time?
-
Is it okay to use an endless loop inside of them? Or should I trigger them somehow?
如果我去找一个简单的 hello world
:
myworker.php
<?php
error_log( "Hello world. This is the worker talking." );
?>
然后(部署或重启后) heroku logs --tail --ps worker
仅向我显示:
2017-08-31T17:46:55.353948+00:00 heroku[worker.1]: State changed from crashed to starting
2017-08-31T17:46:57.834203+00:00 heroku[worker.1]: Starting process with command `php worker/mailer.php`
2017-08-31T17:46:58.452281+00:00 heroku[worker.1]: State changed from starting to up
2017-08-31T17:46:59.782480+00:00 heroku[worker.1]: State changed from up to crashed
2017-08-31T17:46:59.773468+00:00 heroku[worker.1]: Process exited with status 0
2017-08-31T17:46:59.697976+00:00 app[worker.1]: Hello world. This is the worker talking.
这是预期的行为吗?
(我不习惯在命令行中使用PHP,这正是工作人员似乎正在做的事情,并且可能解释了我的一些困惑 . )
背景:我试图了解它们是如何工作的,但也是为了帮助我决定是否应该使用 worker
或 clock
来自制邮件/新闻通讯系统我正在适应Heroku .