php 用于通过cURL测试收集WordPress站点和服务器信息的独立脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 用于通过cURL测试收集WordPress站点和服务器信息的独立脚本相关的知识,希望对你有一定的参考价值。

<?php
/**
 * Script Name: WPMU DEV SLS Diagnostics
 * Script URI:  https://premium.wpmudev.org/
 * Description: Misc diagnostic tools used by WPMU DEV SLS Tech Support
 * Author:      WPMU DEV
 * Version:     0.5.2
 * Author URI:  https://premium.wpmudev.org/
 *
 */
   error_reporting(E_ALL);
   ini_set('display_errors', 1);
   ?>
<!DOCTYPE html>
<head>
   <meta name="robots" content="noindex, nofollow" />
   <title>Quick Diagnostics</title>
   <style type="text/css" media="screen">
      body{
      padding:0px;
      margin:0px;
      text-align:left;
      font-size:12px;
      font-family:"Lucida Console", Monaco, monospace;
      }
      #content{
      padding:1em 2em;
      }
      pre{
      height:250px;
      overflow:scroll;
      background:#efefef;
      border:1px solid silver;
      padding:0 1em;
      }
   </style>
</head>
<body>
   <!-- cURL Test 3 - Uncomment to run. //-->
   <!--
      <?php
         $ch = curl_init("https://premium.wpmudev.org/api/dashboard/v1/");    // initialize curl handle
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         $data = curl_exec($ch);
         print($data);
          ?>
      <style type="text/css" media="all">
         body{
         background: black;
         color: white;
         }
         #content{
         display:none !important;
         }
      </style>
      //-->
   <div id="content">
      <h1>Quick Diagnostics</h1>
      <hr />
      <?php
         $du = shell_exec('du -hs .');
         $ls = shell_exec('ls -al .');
         $cat = shell_exec('cat ./wp-content/debug.log'); 
         ?>
      <h2>Current Disk Usage</h2>
      <p><?php echo $du; ?></p>
      <h2>Current Directory Listing</h2>
      <pre><?php echo $ls; ?></pre>
      <h2>cURL Test 1</h2>
      <pre><?php
         if (isDEVAvailible('https://premium.wpmudev.org'))
         {
                 echo "<h2>premium.wpmudev.org is Up and running!</h2>";
         }
         else
         {
                 echo "<h2>Whoops, nothing found at premium.wpmudev.org.</h2>";
         }
         
         //returns true, if domain is availible, false if not
         function isDEVAvailible($domain)
         {
                 //check, if a valid url is provided
                 if(!filter_var($domain, FILTER_VALIDATE_URL))
                 {
                         return false;
                 }
         
                 //initialize curl
                 $curlInit = curl_init($domain);
                 curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
                 curl_setopt($curlInit,CURLOPT_HEADER,true);
                 curl_setopt($curlInit,CURLOPT_NOBODY,true);
                 curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);
         
                 //get answer
                 $response = curl_exec($curlInit);
         
                 curl_close($curlInit);
         
                 if ($response) return true;
         
                 return false;
         }
         if (isGoogleAvailible('https://google.com'))
         {
                 echo "<h2>google.com is Up and running!</h2>";
         }
         else
         {
                 echo "<h2>Whoops, nothing found at google.com.</h2>";
         }
         
         //returns true, if domain is availible, false if not
         function isGoogleAvailible($domain)
         {
                 //check, if a valid url is provided
                 if(!filter_var($domain, FILTER_VALIDATE_URL))
                 {
                         return false;
                 }
         
                 //initialize curl
                 $curlInit = curl_init($domain);
                 curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
                 curl_setopt($curlInit,CURLOPT_HEADER,true);
                 curl_setopt($curlInit,CURLOPT_NOBODY,true);
                 curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);
         
                 //get answer
                 $response = curl_exec($curlInit);
         
                 curl_close($curlInit);
         
                 if ($response) return true;
         
                 return false;
         }?></pre>
      <h2>cURL Test 2</h2>
      <pre><?php 
         $ch = curl_init('https://premium.wpmudev.org/api/dashboard/v1/');
         curl_setopt($ch, CURLOPT_CONNECT_ONLY, true);
         curl_exec($ch);
         $getinfo = curl_getinfo($ch);
         $out = '';
         foreach($getinfo as $key => $value) {
             $title = "<strong>" . $key . "</strong>";
             if( is_array( $value ) ){            
                 $content = '';           
                 if( ! empty( $value ) ){
                     foreach( $value as $k => $v ){            
                     $sub_title = '<strong>' . $k . '</strong>';            
                     $content .= "<span style=''padding-left: 20px'>\n";
                         $content .= $sub_title .' : ';
                         $content .= $v;
                     $content .= "</span>\n"; 
                     }
                 }
             }
             else{
                 $content = $value;
             }                
             $out .= $title . ': ' . $content . "\n";
         }
         echo $out;
         curl_close($ch);
         ?></pre>
      <h2>debug.log output</h2>
      <pre><?php echo $cat; ?></pre>
      <h2>PHPInfo</h2>
      <pre><?php phpinfo(); ?></pre>
   </div>
</body>
</html>

以上是关于php 用于通过cURL测试收集WordPress站点和服务器信息的独立脚本的主要内容,如果未能解决你的问题,请参考以下文章

wordpress 下载主题模板更新报错 No working transports found解决办法

WP Plugin 中的异步 php 代码

WORDPRESS : cURL 错误 60: SSL 证书

信息收集 -- WordPress网站

markdown 链接,片段,提醒,收集点作为重新访问WordPress插件开发期间的笔记#WordPress #Plugin #PHP #Refere

Curl 和 PHP - 如何通过 curl 通过 PUT、POST、GET 传递 json