Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检测php文件\u get\u内容中的远程分析错误_Php_Remote Access - Fatal编程技术网

检测php文件\u get\u内容中的远程分析错误

检测php文件\u get\u内容中的远程分析错误,php,remote-access,Php,Remote Access,我的问题类似于,但不完全相同 如果我执行$string=@file\u get\u contents('http://www.somesite.com/script.php');并且script.php中有一个解析错误,$string获取解析错误的值,而不是bool false。错误不在本地站点上,而是在远程站点上 我想我必须进行字符串比较以检查这种情况,但是是否有一个特定字符串的列表,我应该查找,例如'Parse error:'和'Warning:'?是否有更好的方法检查远程脚本上的错误 (我

我的问题类似于,但不完全相同

如果我执行
$string=@file\u get\u contents('http://www.somesite.com/script.php');
并且script.php中有一个解析错误,
$string
获取解析错误的值,而不是bool false。错误不在本地站点上,而是在远程站点上

我想我必须进行字符串比较以检查这种情况,但是是否有一个特定字符串的列表,我应该查找,例如
'Parse error:'
'Warning:'
?是否有更好的方法检查远程脚本上的错误

(我可以控制这两个领域,以防这会影响你的建议。)

以下是我在远程服务器上输入的代码:

  if(!$_SERVER['QUERY_STRING'])
    {
      echo('Can you get me?');
    }
  else
    {
      foreach ($imnotanarray as $fail) //intentionally cause an error
        {
          echo $fail;
        }
    }
这是来自本地服务器的代码

$success=file_get_contents('http://www.tecbrat.com/fgc_responder.php');
$success_header=$http_response_header[0];

$failure=file_get_contents('http://www.tecbrat.com/fgc_responder.php?do=fail');
$failure_header=$http_response_header[0];

$failure2=@file_get_contents('http://www.tecbrat.com/fgc_responder.phxp');
$failure2_header=$http_response_header[0];

echo 'Success is '.$success.'and the header is '.$success_header."<br><br>\n\n";
echo 'Failure is '.$failure.'and the header is '.$failure_header."<br><br>\n\n";
echo 'Another Failure is ';
var_dump($failure2);
echo ' and the header is '.$failure2_header;
$success=file\u get\u contents('http://www.tecbrat.com/fgc_responder.php');
$success_header=$http_response_header[0];
$failure=file\u get\u contents($failure)http://www.tecbrat.com/fgc_responder.php?do=fail');
$failure_header=$http_response_header[0];
$failure2=@file\u get\u contents('http://www.tecbrat.com/fgc_responder.phxp');
$failure2_头=$http_响应_头[0];
echo“Success是“.$Success.”,标头是“.$Success\u标头。”

\n\n; 回显“Failure”为“.$Failure”,标题为“.$Failure\u header”。

\n\n”; 回声“另一个失败是”; var_转储($failure2); echo'和标头为'.$failure2_标头;
使用该输出,使用子字符串匹配搜索解析错误确实是最好的选择


如果您觉得这样做不雅观-您这样认为是完全正确的-正确的处理方法是添加一些错误处理,并以更集成的方式表示解析错误,因此,如果您的服务通常返回一个XML对象或其他内容,它将返回一个包含错误数据的XML对象。

PHP错误通常伴随500 http状态代码。我不确定您是否可以通过file_get_内容捕捉到这一点,但您可以使用我不确定,但不解析错误抛出HTTP 500来实现这一目标?也许你可以检查一下?不,我的测试脚本说:
失败是解析错误:语法错误,在第9行的/home/tecbrat/public\u html/fgc\u responder.php中出现意外的T\u FOREACH,标题是HTTP/1.1200 OK
我在我的问题中添加了一些代码。你知道所有php错误是否总是以
'
开头吗?在这个特定的例子中,预期的返回是纯文本,但我认为它永远不会以该字符串开头。我认为没有必要验证它是否为粗体,对吗?您可以始终通过HTML净化器运行结果,这样您就可以检查纯文本了。我发现,至少在我的服务器上,

\n错误类型”
在一开始就出现了错误,因此我将检查

\n”