Well, to start with, what exactly are you getting with this part?
$ping = shell_exec('/bin/ping -c 1 -q '. $host);
Are you sure the string "100% packet loss" is in there, and if so, remember strstr() is case-sensitive. Maybe you should first check that $ping is not empty?