来自服务器的响应延迟超过24小时 - 是否可能?

php: My question is about the project that I want to develop using LAMP (Linux, Apache, mysql, php,) and html on the server with a shared hosting.

I want a user to enter a number into the <input type="text"> on my web-page, click "get the result" and get the result (display at another page or use ajax request - whatever).

To calculate the result it takes up to 24 hours. Is it possible to write such a project so the user's browser wait up to 24 hours? Are there any limit on dialogues between user's browser and server with a shared hosting? I mean is it limited by less than 24 hours?

Should I try this project or I'd better write it using another technologies?

Technically, yes, you can do ajax long-polling. A request stays open as long as you need it to (consuming web server resources) until the response is generated and returned to the user. Whether it's a good idea or not... You can't really expect a user to keep a browser window open for that long. And that's just one reason.

It's easier on both the browser and server if you store the timestamp of when you inputted the number, and calculate the response on the server.

Afterwards you can use ajax polling to check whether 24 hours have passed. I wouldn't recommend server push in this case, as I wouldn't like to have a browser open for that long of a duration.

If you need to process the form request, you could have the controller fork a new process in which to do the calculations. The response back to the user would then happen straight away - letting you tell them the results will be emailed (ideally) or shown on page refresh when their finished.

http://php.net/manual/en/function.pcntl-fork.php

if (isset($_POST['form'])) {

    // Form validation, etc.

    if ($pid = pcntl_fork()) {
        echo 'Your results will be ready eventually...';
        exit;
    }

    // Process the input here in detached daemon process.
}

From a UX perspective, this is not really feasible.

While it may be possible to have the client wait that long, you would inevitably run into issues with timeouts on the web server, with the client browser, with the client operating system, and with possible intermediate proxy servers. TCP isn't designed to hold connections open that long.

Instead, you should accept the request and return the header HTTP/1.0 202 Accepted to indicate that the request was successful and processing, and then send a push notification (such as an e-mail) and/or let the user check a status page that can refresh periodically.