In
$stream = fopen("ssh2.sftp://$sftp/path/to/file", 'r');
please make sure that you are specifying the "absolute" path to a file.
If not, you'll get errors like
"Unable to open file ..."
The reasoning is simple ... ssh2.sftp://$sftp points to the "root" directory on the remote server, where, most likely, one does not have access.
It is necessary to point it to your "home" directory. For example, "ssh2.sftp://$sftp/home/username/filename" ... where "/home/username" is where your home directory is.