Determine in php script if connected to internet?

前端 未结 11 1041
轮回少年
轮回少年 2020-11-30 21:28

How can I check if I\'m connected to the internet from my PHP script which is running on my dev machine?

I run the script to download a set of files (which may or ma

11条回答
  •  青春惊慌失措
    2020-11-30 21:48

    You could ping to a popular site or to the site you're wgetting from (like www.google.nl) then parse the result to see if you can connect to it.

    &1", $output, $retval);
    if ($retval != 0) { 
    echo "no!"; 
    } 
    else 
    { 
    echo "yes!"; }
    ?>
    

提交回复
热议问题