Might I suggest switching to phpseclib, it's so much easier to use and has built in debugging. Here's your same script using phpseclib (I used my own code for the adduser part, because I know it works):
<?php
ini_set('max_execution_time', 60);
define("_VALID_PHP", true)...