ping is not used to check just a port, it's used to check if a computer is online...
Are you trying to see if a port is open? If you are, then use fsockopen() to connect to that port. If the function returns a valid socket handle, then the port is open. If it returns false, then the port is not open.
Diego