简体   繁体   English

heroku php 增加 max_execution_time

[英]heroku php increase max_execution_time

I have a telegram Bot hosted on Heroku.我有一个电报机器人托管在 Heroku 上。

It needs to grab some content from a website Parse it and send a messege to the user它需要从网站上抓取一些内容解析它并向用户发送消息

$params['text'] = getRemoteContent("https://example.com/someData");

$t->send('sendMessage', $params);

but it exits after 30 seconds但它会在 30 秒后退出

2020-12-23T15:04:54.995957+00:00 app[web.1]: [23-Dec-2020 15:04:54] WARNING: [pool www] child 295, script '/app/index.php' (request: "GET /index.php?q=data&chat_id=000672000") execution timed out (30.626797 sec), terminating

I tried .user.ini but no change in results it still exits after 30 seconds我尝试了 .user.ini但结果没有变化,它在 30 秒后仍然退出

max_execution_time = 400

try to reset your apache after change php.ini.尝试更改 php.ini 后重置您的 apache。

other way, write其他方式,写

<?
set_time_limit(50);
//your code

This is a bad practice, it is better to write code that will shorten the loading time, for example to make processes work in parallel.这是一种不好的做法,最好编写可以缩短加载时间的代码,例如使进程并行工作。

updating : I saw you running on the "heroku".更新:我看到你在“heroku”上运行。 From a peek at their documentation, if you have to go over the 30s request timeout, you'll need to use a background job:从他们的文档中可以看出,如果您必须在 30 秒的请求超时内访问 go,则需要使用后台作业:

https://devcenter.heroku.com/articles/request-timeout https://devcenter.heroku.com/articles/request-timeout

  • Web requests on Heroku come with a 30-second limit. Web 对 Heroku 的请求有 30 秒的限制。 From their Request timeout article:从他们的请求超时文章中:

Web requests processed by Heroku are directed to your dynos via a number of Heroku routers.由 Heroku 处理的 Web 请求通过多个 Heroku 路由器定向到您的测功机。 These requests are intended to be served by your application quickly.这些请求旨在由您的应用程序快速处理。 Best practice is to get the response time of your web application to be under 500ms [...] Occasionally a web request may hang or take an excessive amount of time to process by your application.最佳做法是让您的 web 应用程序的响应时间低于 500 毫秒 [...] 有时,web 请求可能会挂起或花费过多的时间来处理您的应用程序。 When this happens the router will terminate the request if it takes longer than 30 seconds to complete.发生这种情况时,如果完成时间超过 30 秒,路由器将终止请求。

Now this goes into more details and mentions an additional 55-second window: HTTP timeouts (in their article about Limits .)现在详细介绍并提到额外的 55 秒 window: HTTP 超时(在他们关于限制的文章中。)

Connections to one-off dynos will be closed after one hour of inactivity与一次性测功机的连接将在不活动一小时后关闭

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM