我可以对同一台服务器执行CURL请求吗

我可以对同一台服务器执行CURL请求吗

本文介绍了我可以对同一台服务器执行CURL请求吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello stackoverflow社区,我需要实现一种方法来对位于同一服务器或另一个服务器上的页面进行POST调用。我们不能使用include,因为我们调用的文件通常调用不同的数据库或具有相同名称的函数。

Hello stackoverflow community, I need to implement a way to make POST calls to pages located on the same server or in another server. We cannot use include because the files that we are calling usually call different databases or have functions with the same name.

我一直在尝试使用curl来实现它,虽然它从另一个服务器调用文件时工作得很好,但是当调用同一个服务器文件所在的位置。

I've been trying to implement this using curl, and while it works perfectly when calling files from another server, I get absolutely nothing when making a call to the same server where the file is.

提前感谢。

编辑添加一些代码:
简化版本的'm in:

EDIT TO ADD SOME CODE:A simplified version of what I'm doing:

File1.php

File1.php

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "www.myserver.com/File2.php");
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>

File2.php

File2.php

<?php
echo "I'M IN!!";
?>

在调用File1.php之后,我什么都不会得到,但如果File2.php在另一个服务器,得到结果。
任何帮助?

After calling File1.php, I get nothing, but if File2.php is in another server then I get a result.Any help?

我尝试使用服务器URL(http ...)和文件的总地址(/ home / wwww ... 。)

I tried using both the server URL (http...) and the total address of the files (/home/wwww....)

推荐答案

请注意,如果您向自己的网站发出CURL请求,处理程序,并且您通过CURL请求的页面使用与生成请求的页面相同的会话,您将遇到死锁情况。

Be aware that if you're issuing the CURL request to your own site, you're using the default session handler, and the page you're requesting via CURL uses the same session as the page that's generating the request, you'll run into a deadlock situation.

默认会话处理程序在页面请求的持续时间内锁定会话文件。当您尝试使用同一会话请求另一个页面时,后续请求将挂起,直到请求超时或会话文件可用。由于你正在做一个内部CURL,所以运行CURL的脚本将保持对会话文件的锁定,并且CURL请求永远不能完成,因为目标页面永远不能加载会话。

The default session handler locks the session file for the duration of the page request. When you try to request another page using the same session, that subsequent request will hang until the request times out or the session file becomes available. Since you're doing an internal CURL, the script running CURL will hold a lock on the session file, and the CURL request can never complete as the target page can never load the session.

这篇关于我可以对同一台服务器执行CURL请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 17:26