在 PHP 中控制不同脚本之间的应用程序流
我有一个 php 脚本,它接受 POST 请求作为 Web 服务的侦听器,然后将所有数据处理到两个最终数组, 我正在寻找一种方法来启动第二个脚本,获取那些序列化数组并进行更多处理。 include() 对我来说不会有好处,因为我实际上想在传递数据后“释放”或“结束”第一个脚本,
一如既往地非常感谢您的帮助:)
编辑 - 好吧,看起来队列可能是解决方案!在任何示例或参考之前我从未做过类似的事情吗?
i have a php script that accepts a POST request as a listener to a web service then process all the data to two final arrays,
I'm looking for a way to initiate a second script that GET's those serialized arrays and do some more processing.
include() will not be good for me since i actually want to "free" or "end" the first script after passing the data
your help is much appreciated as always :)
EDIT - OK so looks like queue might be the solution! i never did anything like this before any examples or reference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
需要立即发生吗?否则,您可以设置一个 cronjob,每 X 分钟执行一次。您必须创建某种队列,在其中第一个脚本将“请求”粘贴到第二个脚本。然后 cronjob 处理队列中的请求。
Does it need to happen immediately? Otherwise you could set up a cronjob that does that every X minutes. You'll have to make some kind of queue in which your first script sticks "requests" to the second script. The cronjob then processes the requests in the queue.
您应该养成编写只是函数集合的 php 脚本的习惯(本身没有自动运行脚本)。这样,您可以在您所讨论的脚本顶部包含一个脚本文件,然后调用执行您想要的操作的函数。
例如:
事实上:
只是为了与我所说的保持一致:
显然你应该使用更好的函数&变量名,哈哈
You should get into the habit of writing php scripts that are just a collection of functions (no auto-ran scripts, per se). This way you can include a script file at the top of the script your talking about and then call the function that does what you want.
For instance:
In Fact:
Just to be consistent with what I'm saying:
Obviously you should use better function & variable names, haha.
我会在一个请求中完成这一切。它减少了延迟并使整个操作更加高效。
请记住,您可以有一个长时间运行的请求,但仍然为其他请求提供服务。 Apache 将生成另一个 php 进程来处理来自 Web 服务的其他请求,即使第一个请求尚未完成。只要脚本不锁定共享资源(数据库文件等),这就可以正常工作。
也就是说,您应该使用 cURL 来调用第二个脚本。然后发布未序列化的数组。 cUrl 将处理剩下的事情。
I'd do it all in one request. It cuts down on latency and makes the whole operation more efficient.
Remember you can have a long running request, but still service other requests. Apache will just spawn another php process to handle the other request from the webservice even though the first has not completed. As long as the script doesn't lock a shared resource (database file etc) this will work just fine.
That said, you should use cURL to call the second script. then post the unserialized array. cUrl will handle the rest.