Problem with wp_insert_post

Because you mention an infinite I am guessing that you are hooked into a hook like save_post that fires for wp_insert_post() so if you hook your code into that your code will run then fire the same hook over and over.

To avoid that remove the action from the top of your callback:

remove_action('save_post','yourcallbackfunctionname');
$my_post = array(
    // ...
 );
 $post_id = wp_insert_post( $my_post, true );