PHP:在多个请求中保持与API的HTTPS连接打开

编程入门 行业动态 更新时间:2024-10-26 22:23:35
本文介绍了PHP:在多个请求中保持与API的HTTPS连接打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为wordpress编写一个插件,该插件需要针对用户的每个请求调用一个API.

I'm writing a plugin for wordpress that needs to call an API for every request the user makes.

这些API调用是使用HTTPS协议完成的.当前,对于每个新用户请求,我都需要重新打开HTTPS连接.

These API-calls are done using the HTTPS protocol. Currently, for every new user request, I need to reopen the HTTPS connection.

是的,curl允许持久连接(重用手柄或使用多手柄),但我想在多个用户请求中保持连接.

Yes, curl allows persistent connections (reusing the handle or using the multi handle) but I would like to persist the connection throughout multiple user requests.

那么:是否可以通过多个PHP进程保持HTTPS连接打开并重用它?另一种选择是让用户的浏览器进行API对话.但是,如果有可能,我想避免这种情况.

So: Is it possible to keep a HTTPS connection open throught multiple PHP processes and reuse it? The alternative would be to let the user's browser to the API-talk. But if it is possible I would like to avoid that.

推荐答案

我最终通过浏览器发出了这些请求.当服务器告诉浏览器时,浏览器使HTTP(S)连接保持打开状态.

I ended up making these requests through the browser. Browsers keep HTTP(S) connections open when the server tells them to.

A,此解决方案存在一些缺点:

Alas, this solution entails some disadvantages:

  • 认证比较困难
  • 由于必须维护更多连接,服务器上的负载更多
  • 该解决方案需要其他JavaScript

但是请求要快得多(大约3倍),并且运行WordPress的服务器上的负载被最小化了.

But requests are much faster (about 3x) and load on the server where WordPress is running is minimized.

更多推荐

PHP:在多个请求中保持与API的HTTPS连接打开

本文发布于:2023-11-06 17:46:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564371.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   PHP   HTTPS   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!