Yes, it can be done with php/WordPress. There is some example code here. It assumes that the WP Discourse plugin is activated. but it could be used without it by supplying values for the api_key, api_username etc.
Also, take a look at the Discourse API Docs.
Depending on when you need this done, the WP Discourse plugin needs to have an API function added to it for creating Discourse users. Once that’s in place, you’ll be able to call something like DiscourseUtilities::create_discourse_user( $wp_user ); That can be added soon, It’s needed for allowing the plugin to work with WordPress membership plugins.