Determine in php script if connected to internet?

前端 未结 11 1047
轮回少年
轮回少年 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:56

    The accepted answer did not work for me. When the internet was disconnected it threw a php error. So I used it with a little modification which is below:

    if(!$sock = @fsockopen('www.google.com', 80))
    {
        echo 'Not Connected';
    }
    else
    {
    echo 'Connected';
    }
    

提交回复
热议问题