Keep-alive in curl / php

偶尔善良 提交于 2019-12-08 05:16:01

问题


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?


回答1:


Generally speaking, every request exists independent of every other request. Connections and other resources are not pooled between requests.

There are possible solutions

  1. 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.

  2. 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/



来源:https://stackoverflow.com/questions/6374738/keep-alive-in-curl-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!