Beware of the tilde (~) in the key file paths, as they will trigger the following warning (on a debug build):
PHP Warning: String is not zero-terminated (ZZZZZZZZZZZZZZZZZZ1wjj*=?<) (source: Zend/zend_execute.h:81) in Unknown on line 0
although the authentication will suceed.
<?php
$ssh_conn = ssh2_connect('test.host.com', 22, array('hostkey' => 'ssh-rsa'));
ssh2_auth_pubkey_file($ssh_conn, 'user', '~/.ssh/id_rsa.pub', '~/.ssh/id_rsa')
?>
The above code will throw the Warning.
<?php
$ssh_conn = ssh2_connect('test.host.com', 22, array('hostkey' => 'ssh-rsa'));
ssh2_auth_pubkey_file($ssh_conn, 'user', '/home/user/.ssh/id_rsa.pub', '/home/user/.ssh/id_rsa')
?>
The above code won't.
If you want to perform a dynamic replacement of the tilde, you can use posix_getpwuid (http://php.net/manual/en/function.posix-getpwuid.php)