As you are in the unix environment, you can always make and then call a shell script to handle the looping and waiting. But I'm surprised that you can't do that inside of php.
Also, i'm not sure about your sample ping command, the 2 different environments I checked seem to have different meanings for the options you mention than what you seem to intend. Try man ping
OR ping --help
The script below should give you a framework for implementing a ping-retry, but I can't spend a lot of time on it.
cat pingCheck.sh
#! /bin/bash -vx
IPaddr=$1
: ${maxPingTries:=3}
echo "maxPingTries=${maxPingTries}"
pingTries=0
while ${keepTryingToPing:-true} ; do
if ping -n 3 -r 1 ${IPaddr} ;then
keepTryingToPing=false
else
sleep ${sleepSecs:-3}
if (( ++pingTries >= maxPingTries )) ; then
printf "Execeeded count on ping attempts = ${maxPingTries}
" 1>&2
keepTryingToPing=false
fi
fi
done
I hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.