首页 > 解决方案 > 如何在不增加执行时间的情况下修复超过 30 秒的最大执行时间?

问题描述

我开发了这个脚本,它可以在线浏览我的文件夹并检查文件夹中的 php 文件,并将它们与本地的 php 文件列表进行比较,以确定我的网站是否已被黑客入侵,黑客可能已将 php 文件存放在我的服务器。如果在我在本地 127.0.0.1 上时有一个我没有亲自输入到数据库中的新文件,脚本将向我发送一封邮件,要求我检查该文件。我的问题是我不断收到 致命错误:超过 30 秒的最大执行时间。如何在不增加执行时间的情况下解决它?

这是我的脚本

<?php require('mettre_avant_haut.php');

?>  <h3 align='center'>This Code scans your Hosting for malicious Php files. If potential viruses are found, there will be displayed below this message</h3> 

<?php $host_actuel = $_SERVER['HTTP_HOST'];

$url_dossier_actuel = url_dossier_actuel($mettre_https='Oui');

function afficher_php($dir='.')    {    global $host_actuel;      global $url_dossier_actuel;
        require('configurations.php');  



          if (is_dir($dir)) {       $objects = scandir($dir);       foreach ($objects as $object) {
          if ($object != "." && $object != "..") {          if (filetype($dir."/".$object) == "dir")            {
               afficher_php($dir."/".$object);              }           else            {
                //unlink   ($dir."/".$object);

                $fichier_actuel = "$dir/$object";

                $ficher_a_inserer = str_ireplace('./','', $fichier_actuel);


                if(preg_match("/.php/i", $ficher_a_inserer))
                {


                //Si on est sur le dossier local, on verifie
                // Pour voir si le ficher php est deja dans la base de donne
                $verification = mysqli_query($connection, "SELECT `nom_fichier` FROM `ojm_all_php_files` WHERE `nom_fichier`='$ficher_a_inserer' LIMIT 1 ") or die(trigger_error("Error on file $ficher_a_inserer").mysqli_error($connection));

                    $compter = mysqli_num_rows($verification);

                    mysqli_free_result($verification);
                        /*  Si le compte donne 0 est que on est sur le local alors on enregistrre le fichier    Autrement on m'envoit un mail pour expliquer que ce ficher est suspect  */
                    if($compter==0)
                    {           #########################################################
             $id_ojm_peoples = @$_SESSION['id_ojm_peoples'];

$ip = getenv('HTTP_CLIENT_IP')?: getenv('HTTP_X_FORWARDED_FOR')?: getenv('HTTP_X_FORWARDED')?: getenv('HTTP_FORWARDED_FOR')?: getenv('HTTP_FORWARDED')?: getenv('REMOTE_ADDR');

$date_created = date('Y-m-d');


//Si le id_ojm_peoples est superieur a 0 alors on verifie a base de ca autrement on verifie a base de ip            if($id_ojm_peoples>0)           {
                $champs_a_utiliser = 'id_ojm_peoples';
                $valeur_champs_a_utiliser = $id_ojm_peoples;

            }           else            {
                $champs_a_utiliser = 'ip';
                $valeur_champs_a_utiliser = $ip;

            }
                    ###########################################
                        //On enregistre le fichier car on est en local
                        //sI ON est en local
                        if(preg_match('/127.0.0.1/i', $host_actuel))
                        {
                            $insertion = mysqli_query($connection, "INSERT INTO `ojm_all_php_files`         VALUES(NULL, '$ficher_a_inserer', '$valeur_champs_a_utiliser', '$date_created')         ") or die(mysqli_trigger_error("Error while inserting the local file in the database").mysqli_error($connection));

                            echo "<br>$ficher_a_inserer has been added as a new local file";

                        }
                        else
                        {
                            //Si on nest pas en local
                            //Ca signifie qu'on est en ligne et que ce fichier nest pas
                            //dans la base de donnee donc un nouveau fichier

                             //Alors on envoit un mail

################################################################## //On envoit un mail a ladmin

////////////////////////////////////////////   //On envoit un mail de dmande de verification de compte $nom_expediteur = "iUseFaith Robot";         $email_expediteur = 'no-reply@mywebsite.com';       $email_destinataire = 'myemail@gmail.com'; 

            $sujet = "Suspect $url_dossier_actuel / $ficher_a_inserer";         $message_html = "    On your website $url_dossier_actuel,  the file <strong> $ficher_a_inserer </strong> seems either not to have been on your local server or you did not update the table named <strong>ojm_all_php_files</strong> with the name of the new file.<br><br>       If that file is not a hacked file, kindly update the table <strong>ojm_all_php_files</strong> localy by going to the website localy and accessing the file <strong>afficher_php.php</strong>. <br>

Afterward, kindly copy the new table <strong>ojm_all_php_files</strong> to your hosting.

";      //echo "$message_html";
            //On envoit un mail a l'email du site $envoyer_mail = envoyer_mail($nom_expediteur,$email_expediteur,$email_destinataire,$sujet,$message_html,$message_texte='',$pj='');
##################################################################



  alert_warning(" <b>  <br> $ficher_a_inserer is a php file that was not on your original local webserver but is now on the online webserver. kindly cross check whether you have allowed that file <br> </b> ", $type='danger');





                        }
                        ################################################


                    }





                }
                ############################################
                            }

          }         }       reset($objects);
              }



        }  ############################################################


afficher_php($dir='.');




?>

标签: php

解决方案


推荐阅读