如何在php中保持持久的http连接?

发布于 2024-09-29 02:33:25 字数 405 浏览 3 评论 0原文

我有一个小的 Web 界面,它在服务器上上传文件,然后将该文件转储到 oracle 数据库中。但其中大约有 700 万条记录,Web 服务器在读取和转储该文件时会超时。 有人可以告诉我如何保持该会话处于活动状态,以便在数据库中上传、读取和转储数据时不会超时吗?

伙计们,我说的是用户上传文件并将其转储到数据库中所花费的时间......现在 700 万条记录是巨大的,网络服务器肯定会超时......如果oracle也超时,那么该怎么办......我知道这很令人困惑,但我不想让用户知道他的文件没有转储到数据库中......异步机制不是这个选项案例...我现在正在使用 apache

到目前为止,它是一个简单的脚本,很少有 html 对象和 php。我必须用 php 来实现... =)

期待您的宝贵回复。 谢谢

i've a little web interface which uploads a file on a server and then dumps that file in oracle db. but there are about 7 million records in it and web server get time out while reading and dumping that file.
can someone please tell me how can i keep that session alive so that it doesn't get timeout when uploading, reading and dumping data in db?

guys, i'm talking about the time that will be taken when a user uploads a file and it'll be dumped in db....now 7million records are enormous and the web server will definitely timeout....and if oracle times out as well, then what to do.....i know its confusing but i dont want to let user know that his file isn't dumped in db...asynchronous mechanism isn't an option in this case...i'm using apache at the moment

it is a simple script so far, few html objects and php. and i've to make it in php... =)

anticipating your valuable response.
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彼岸花似海 2024-10-06 02:33:25

要保持脚本运行,请将此代码放在 php 文件的开头。我认为只有当您直接调用该文件时这才有效。我的意思是,我不相信如果包含 php 文件就行不通。

set_time_limit(0);
header('Connection: close');
ignore_user_abort();

从这里开始:
http://php.oregonstate.edu/manual/en/features.connection -handling.php

希望这有帮助,
伊斯梅尔.

To keep script running, put this code at the begining of the php file. I think this works only if you make a direct call to the file. I mean, I don't believe works if the php file are include.

set_time_limit(0);
header('Connection: close');
ignore_user_abort();

From here:
http://php.oregonstate.edu/manual/en/features.connection-handling.php

Hope this helps,
Ismael.

诗化ㄋ丶相逢 2024-10-06 02:33:25

不存在“持久 http 连接”这样的东西

如何让该会话保持活动状态

HTTP 是无状态的,因此会话管理不是由协议实现的 - 并且与您描述的问题无关。

网络服务器超时

也许如果您告诉我们它是什么 Web 服务器,那么我们可能能够建议操纵超时的方法。

另外,您没有说明为什么您认为这是一个超时问题,而不是其他问题(例如文件大小限制),并且您没有区分上传和后续数据加载作为脚本失败的点。

....但解决问题的正确方法是在文件上传后启动一个单独的独立进程来执行数据加载。谷歌搜索“长时间运行的 php 进程设置”

There is no such thing as a "persistent http connection"

how can i keep that session alive

HTTP is stateless therefore session management is not implemented by the protocol - and is also nothing to do with the problem you describe.

and web server get time out

Maybe if you had told us what webserver it was then we might have been able to suggest ways of manipulating the timeout.

Also, you don't say why you think that its a timeout issue rather than something else going wrong (e.g. file size limit) and you've not discriminated between the upload and subsequent dataload as the point at which the script fails.

....but the right way to solve the problem would be to launch a seperate, independent process to carry out the dataload after the file has uploaded. Have a google for 'Long running php process setsid'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文