后台 PHP 工作者

发布于 2024-12-17 00:55:47 字数 183 浏览 0 评论 0原文

我有一个需要一段时间来处理的脚本,它必须从数据库中获取内容并将数据传输到其他服务器。

目前,我让它在提交表单后立即执行此操作,并且需要花费时间来传输该数据才能表明其已发送。

我想知道无论如何都要做到这一点,这样它就不会在客户面前执行该过程?

我不需要 cron,因为它需要同时发送,但不与客户端一起加载。

I have a script that takes a while to process, it has to take stuff from the DB and transfers data to other servers.

At the moment i have it do it immediately after the form is submitted and it takes the time it takes to transfer that data to say its been sent.

I was wondering is the anyway to make it so it does not do the process in front of the client?

I dont want a cron as it needs to be sent at the same time but just not loading with the client.

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

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

发布评论

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

评论(2

一身骄傲 2024-12-24 00:55:47

几个选项:

  1. Exec PHP 脚本,从您的网页执行数据库工作,但不等待 exec 的输出。对此要非常小心,不要盲目接受用户的任何输入参数而不对其进行清理。我只是将其作为一个选项提到,我自己永远不会这样做。

  2. 让数据库更新脚本始终在后台运行,轮询是否发生触发其更新的事件。例如,它可能会检查 /tmp/run.txt 是否存在,如果存在则启动数据库更新。然后,您可以从网页创建 run.txt 并返回,而无需等待响应。

  3. 将数据库更新脚本创建为守护程序。

A couple of options:

  1. Exec the PHP script that does the DB work from your webpage but do not wait for the output of the exec. Be VERY careful with this, don't blindly accept any input parameters from the user without sanitising them. I only mention this as an option, I would never do it myself.

  2. Have your DB updating script running all the time in the backgroun, polling for something to happen that triggers its update. Say, for example, it could be checking to see if /tmp/run.txt exists and will start DB update if it does. You can then create run.txt from your webpage and return without waiting for a response.

  3. Create your DB update script as a daemon.

孤君无依 2024-12-24 00:55:47

您可以查看以下内容:

您要传输多少数据,传输是否更像是仅复制粘贴数据,还是将数据从数据库插入目标服务器,然后从源中删除数据?

你可以尝试分析你的SQL,看看是否有优化的空间。

然后,您还可以检查您的 php 代码,看看是否有任何东西(即使是最轻微的)可能有助于更快地执行必要的任务。

源数据库服务器和目标数据库服务器位于何处(如果您碰巧知道的话,就网络和地理位置而言)以及源服务器和目标服务器通过网络进行通信的速度有多快?

Here are some things you can take a look at:

How much data are you transferring, and by transfer is it more like a copy-and-paste the data only, or are you inserting the data from your db into the destination server and then deleting the data from your source?

You can try analyzing your SQL to see if there's any room for optimization.

Then you can check your php code as well to see if there's anything, even the slightest, that might aid in performing the necessary tasks faster.

Where are the source and destination database servers located (in terms of network and geographically, if you happen to know) and how fast the source and destination servers are able to communicate through the net/network?

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