简体   繁体   中英

PHP Restart php script after EXIT?

I have a php script : I put a list of website in a textarea and the php script check if websites are down or UP . My problem : When a website is down , the script show me an error and stop working with the rest of the list :

Warning: fsockopen() [function.fsockopen]: unable to connect to http://SITEDOWN.com:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home/checklist/public_html/checklist.php (1) : eval()'d code(1) : eval()'d code(1) : eval()'d code on line 109

when a website is down it show me this error and then the checker stop doing his work and stop all , to fix the error i made this ( i added the DIE to the script) :

<?php
    public function sendpacket($host,$packet,$response = 0,$output = 0) 
    {
    $ock = fsockopen($host,80);
    stream_set_timeout($ock,5);
    if (!$ock) 
    {
    echo '=> Site down<br/>'; 
    die;

}

then it dont show me the error but the php script automatically stop when a website is down (It show me SITE DOWN and stop all , no continue with others sites ) I want : When a website is down , it show me "Site Down" and php script restart/CONTINUE with the following line (i use textarea , 1site per line )

Sorry for my bad english and thanks to all memmbers who taken the time to read this

Change die to return false and write your calling script to call the function in an if statement...

    if (sendpacket == false) {
        echo "Fail message";
    } else {
        echo "Success message";
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM