What is the difference between using chmod() and ssh2_sftp_chmod() in PHP for setting file permissions?

When setting file permissions in PHP, using the chmod() function directly modifies the permissions of a file on the local filesystem, while ssh2_sftp_chmod() is used to modify the permissions of a file on a remote server via SSH. If you need to change permissions on a remote file, you should use ssh2_sftp_chmod() instead of chmod().

// Using ssh2_sftp_chmod() to set file permissions on a remote server
$connection = ssh2_connect('example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

$sftp = ssh2_sftp($connection);
ssh2_sftp_chmod($sftp, '/path/to/file.txt', 0644);