Is it possible to increase CloudFlare time-out?

后端 未结 3 1461
眼角桃花
眼角桃花 2021-02-01 16:02

Is it possible to increase CloudFlare\'s time-out? If yes, how?

My code takes a while to execute and I wasn\'t planning on Ajaxifying it the coming days.

相关标签:
3条回答
  • 2021-02-01 16:37

    I know that it cannot be treated like a solution but there is a 2 ways of avoiding this. 1) Since this timeout is often related to long time generating of something, this type of works can be done through crontab or if You have access to SSH you can run a PHP command directly to execute. In this case connection is not served through Cloudflare so it goes as long as your configuration allows it to run. Check it on Google how to run scripts from command line or how to determine them in crontab by using /usr/bin/php /direct/path/to/file.php

    2) You can create subdomain that is not added to cloudlflare and move Your script there and run them directly through URL, Ajax call or whatever.

    There is a good answer on Cloudflare community forums about this:

    If you need to have scripts that run for longer than around 100 seconds without returning any data to the browser, you can’t run these through Cloudflare. There are a couple of options: Run the scripts via a grey-clouded subdomain or change the script so that it kicks off a long-running background process and quickly returns a status which the browser can poll until the background process has completed, at which point the full response can be returned. This is the way most people do this type of action as keeping HTTP connections open for a long time is unreliable and can be very taxing also.

    This topic on Stackoverflow is high in SERPs so I decided to write down this answer for those who will find it usefull.

    0 讨论(0)
  • 2021-02-01 16:43

    No, CloudFlare only offers that kind of customisation on Enterprise plans.

    • CloudFlare will time out if it fails to establish a HTTP handshake after 15 seconds.
    • CloudFlare will also wait 100 seconds for a HTTP response from your server before you will see a 524 timeout error.
    • Other than this there can be timeouts on your origin web server.

    It sounds like you need Inter-Process Communication. HTTP should not be used a mechanism for performing blocking tasks without sending responses, these kind of activities should instead be abstracted away to a non-HTTP service on the server. By using RabbitMQ (or any other MQ) you can then pass messages from the HTTP element of your server over to the processing service on your webserver.

    0 讨论(0)
  • 2021-02-01 16:43

    I was in communication with Cloudflare about the same issue, and also with the technical support of RabbitMQ.

    RabbitMQ suggested using Web Stomp which relies on Web Sockets. However Cloudflare suggested...

    Websockets would create a persistent connection through Cloudflare and there's no timeout as such, but the best way of resolving this would be just to process the request in the background and respond asynchronously, and serve a 'Loading...' page or similar, rather than having the user to wait for 100 seconds. That would also give a better user experience to the user as well

    UPDATE:

    For completeness, I will also record here that I also asked CloudFlare about running the report via a subdomain and "grey-clouding" it and they replied as follows:

    I will suggest to verify on why it takes more than 100 seconds for the reports. Disabling Cloudflare on the sub-domain, allow attackers to know about your origin IP and attackers will be attacking directly bypassing Cloudflare.

    FURTHER UPDATE

    I finally solved this problem by running the report using a thread and using AJAX to "poll" whether the report had been created. See Bypassing CloudFlare's time-out of 100 seconds

    0 讨论(0)
提交回复
热议问题