持久的php连接?
是否可以让php脚本在某个时刻暂停等待ajax响应,然后继续执行?
如果不是,那么存储脚本当前状态(所有定义的变量等)直到再次调用它的最合适的方法是什么?
Is it possible to have a php script pause at a certain point wait for an ajax response, then continue executing?
If not, what is the most appropriate way to store the current state of a script (all defined variables ect) untill it in invoked again?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
让它等待永远不会出现的ajax响应听起来是一个非常糟糕的计划(除了由于http作为无状态协议的性质而不可能实现之外)。
使用 session 保存用户数据(您可以在会话中存储对象)有什么问题?但它不会自动序列化整个状态。
Making it wait for an ajax response which could never come sounds like a very bad plan (apart from being impossible due to the nature of http as a stateless protocol).
What's wrong with using session to persist user data (you can store objects in the session)? It won't serialize the whole state automagically though.
这不是 php 的工作原理,也不是 ajax 的工作原理。每个请求都是独立的。您可以使用会话。
Not how php works, or ajax really either. Each request is independent. You can use a session.
我认为您正在寻找 Comet链接文本 - 这是反向 Ajax 的一种形式它使连接无限期地保持打开状态 - 尽管我认为您不会有一个 PHP 脚本只是等待它......
I think you are looking for Cometlink text - which is a form of reverse Ajax which holds the connection open indefinitely - although I don't think you'd have a PHP script just wait for it...
如果您想获取通常通过 ajax 访问的 php 脚本响应,则只需使用 curl 函数即可。 Curl 将等待响应到达。
If you want to get in your php script response that you would normally access via ajax then just use curl functions. Curl will wait for the response to arrive.