简体   繁体   English

从同一服务器请求页面?

[英]Request page from same server?

I have a website that it consuming it's own API. 我有一个使用它自己的API的网站。 This means sending a request to itself. 这意味着向自身发送请求。

I feel like there might be a way to send a request to a local page quicker than just including the API url. 我觉得有一种方法可以比仅包含API URL更快地将请求发送到本地页面。

Right now I'm doing: file_get_contents("http://domain.com/api/recent") 现在我正在做: file_get_contents("http://domain.com/api/recent")

These didn't work when I tried it: 这些在我尝试时不起作用:
file_get_contents("http://localhost/api/recent") file_get_contents("http://127.0.0.1/api/recent") file_get_contents("http://localhost/api/recent") file_get_contents("http://127.0.0.1/api/recent")

Sorry I can't comment since don't have enough reputation - my 5 cents - 抱歉,我的评论不高-我的5美分-

You could easily use the local API by including / requiring the API php file while setting up all the posted / get variables prior to the inclusion. 您可以通过在包含之前设置所有发布/获取变量的同时包含/需要API php文件来轻松使用本地API。 You could cache them if the user sent you important data and then re-set them from cache. 如果用户向您发送了重要数据,然后从缓存中重新设置它们,则可以缓存它们。

When you call the API with http it is basically slower as it goes through the web server and not through the PHP engine. 当您使用http调用API时,它通过网络服务器而不是通过PHP引擎的速度基本上会变慢。 cheers. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM