Twitter – Delete All DM Using PHP

I had a lot of messages in my Twitter DM box, and I wanted an easy way to get rid of all of them. Therefore, I wrote this script:

<?php
$username = '';
$password = '';

function curl_get_contents($method, $url) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
	$output = curl_exec($ch);
	curl_close($ch);
	return $output;
}
$run = true;
while($run) {
	$out = curl_get_contents('get', 'http://api.twitter.com/1/direct_messages.xml');
	if(strlen($out) < 150) {
		$run = false;
	} else {
 		$xml = simplexml_load_string($out);
 		foreach($xml->direct_message as $msg) {
			$delete = curl_get_contents('delete', 'http://api.twitter.com/1/direct_messages/destroy/' . $msg->id . '.xml');
		}
	}
}
?>

Does it work well for you? Let me know!