Since version 0.13 of the SSH2 extension, it's possible to retrieve the command exit status with stream_get_meta_data().
For example:
<?php
$channel = ssh2_exec($connection, $command);
$metadata = stream_get_meta_data($channel);
$exitCode = $metadata['exit_status'];
?>
Retrieving the exit code is very helpful, since usually, commands return 0 in case of success, and other values in case of errors.