在curl / php中保持活动状态
我正在用 PHP 编写一个网关脚本,它连接到远程服务器,获取一些信息并将其返回以供 JSON 使用(不可能使用 JSONP)。
该网关每秒都会被请求,因此对于 curl
使用 keep-alive 非常重要。据我所知,如果我们在多个请求中使用相同的句柄,curl
会自动执行此操作。
问题是:如何存储两次重新加载之间的句柄?无法将句柄资源存储在会话中,也无法序列化。
或者也许还有其他方法来确保卷曲保持活动状态?
I'm writing a gateway script in PHP which connects to a remote server, obtains some information and returns it for JSON usage (no JSONP possibility).
This gateway is being requested every second, so it's very important for curl
to use keep-alive. From what I learned, curl
will do it automatically if we will use the same handle across multiple requests.
The question is: how do I store the handle between two reloads? It's not possible to store the handle resource in session, it also can't be serialized.
Or maybe there's other way to ensure keep-alive in curl?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,每个请求都独立于其他请求而存在。连接和其他资源不会在请求之间进行池化。
有可能的解决方案
使用具有内容自适应功能的代理(Squid 和 Greasyspoon 可以在这里工作),这确实需要一些工作来设置。但是您将能够用 java、javascript 或 ruby 编写脚本来适应您的内容。
作为守护进程运行 PHP 脚本,有点像网络服务器。这需要一些工程技术,但可以使用 PHP 来完成。您将了解套接字和线程。
您也许可以以此为起点:http://nanoweb.si.kz/
Generally speaking, every request exists independent of every other request. Connections and other resources are not pooled between requests.
There are possible solutions
Use a proxy with content adaptation (Squid and Greasyspoon would work here) this does take some work to set up. But you will be able to write scripts in java, javascript or ruby to adapt your content.
Run your PHP script as a deamon, sort of like a webserver. This would take a bit of engineering, but it can be done with PHP. You would be getting into sockets and threading.
You might be able to use this as a starting point: http://nanoweb.si.kz/