Don't hesitate to test $output === false instead of $output ;)