Your if statement won't show all errors. It will only show an error in the case of error code "1" (which is not an error that limelm.pkey.generate will return. See: https://wyday.com/limelm/help/api/limelm.pkey.generate/
So really you'll never show any error. Which is bad. A better if-statement would be:
if ($xml['stat'] == 'ok'){ echo "success";}else{ echo "error ".$xml->err['code'].': '.$xml->err['msg'];}
Which will print out exactly what the error is, and what the message for the error is.