duanhe0817825 2011-06-16 15:49 采纳率: 100%
浏览 47
已采纳

在curl / php中保持活着

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条回答 默认 最新

  • dongxie3701 2011-06-16 17:02
    关注

    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/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据