Index: wp-includes/functions-post.php
===================================================================
--- wp-includes/functions-post.php	(revision 3330)
+++ wp-includes/functions-post.php	(working copy)
@@ -182,19 +182,16 @@
 		do_action('publish_post', $post_ID);
 
 		if ( !defined('WP_IMPORTING') ) {
-			if ( $post_pingback )
-				$result = $wpdb->query("
-					INSERT INTO $wpdb->postmeta 
-					(post_id,meta_key,meta_value) 
-					VALUES ('$post_ID','_pingme','1')
-				");
-			$result = $wpdb->query("
-				INSERT INTO $wpdb->postmeta 
-				(post_id,meta_key,meta_value) 
-				VALUES ('$post_ID','_encloseme','1')
-			");
+			if ( $post_pingback ) {
+				$result = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE ID = $post_ID AND meta_key = '_pingme'");
+				$result = $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_ID','_pingme','$post_date_gmt')");
+			}
+			$result = $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$post_ID','_encloseme','1')");
 			spawn_pinger();
 		}
+	} elseif ( $previous_status == 'publish' ) {
+		// Remove scheduled pings (in case you unpublish a future post)
+		$result = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE ID = $post_ID AND meta_key = '_pingme'");
 	} else if ($post_status == 'static') {
 		generate_page_rewrite_rules();
 
Index: wp-includes/classes.php
===================================================================
--- wp-includes/classes.php	(revision 3330)
+++ wp-includes/classes.php	(working copy)
@@ -670,6 +670,9 @@
 
 		update_post_caches($this->posts);
 
+		if ( have_pings_in_cache() )
+			spawn_pinger(1);
+
 		$this->posts = apply_filters('the_posts', $this->posts);
 		$this->post_count = count($this->posts);
 		if ($this->post_count > 0) {
Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 3330)
+++ wp-includes/functions.php	(working copy)
@@ -980,21 +980,57 @@
 	}
 }
 
-function spawn_pinger() {
-	global $wpdb;
-	$doping = false;
-	if ( $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' LIMIT 1") )
+function have_pings_in_cache() {
+	global $post_cache, $post_meta_cache;
+
+	$ping = false;
+
+	if ( count($post_cache) ) {
+		foreach ($post_cache as $post)
+			if ( (trim($post->to_ping) != '') && (strtotime($post->post_date_gmt) <= gmdate('U')) ) {
+				$ping = true;
+				break;
+			}
+
+		reset($post_cache);
+	}
+
+	if ( count($post_meta_cache) ) {
+		foreach ($post_meta_cache as $meta)
+			if ( isset($meta['_pingme']) && (strtotime($meta['_pingme']) <= gmdate('U')) ) {
+				$ping = true;
+				break;
+			}
+
+		reset($post_meta_cache);
+	}
+
+	return $ping;
+}
+
+function spawn_pinger($doping = false) {
+	global $wpdb, $spawned_pinger;
+
+	if ( $spawned_pinger > $doping )
+		return;
+
+	$now = gmdate('Y-m-d H:i:59');
+
+	if ( !$doping && $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' AND post_date_gmt <= '$now' LIMIT 1") )
 		$doping = true;
 
-	if ( $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pingme' OR meta_key = '_encloseme' LIMIT 1") )
+	if ( !$doping && $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE (meta_key = '_pingme' AND meta_value <= '$now') OR meta_key = '_encloseme' LIMIT 1") )
 		$doping = true;
 
 	if ( $doping ) {
 		$ping_url = get_settings('siteurl') .'/wp-admin/execute-pings.php';
 		$parts = parse_url($ping_url);
 		$argyle = @ fsockopen($parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01);
+
 		if ( $argyle )
 			fputs($argyle, "GET {$parts['path']}?time=".time()." HTTP/1.0\r\nHost: {$_SERVER['HTTP_HOST']}\r\n\r\n");
+
+		++$spawned_pinger;
        }
 }
 
Index: wp-admin/execute-pings.php
===================================================================
--- wp-admin/execute-pings.php	(revision 3330)
+++ wp-admin/execute-pings.php	(working copy)
@@ -1,30 +1,29 @@
 <?php
+
+ignore_user_abort(true);
+
 require_once('../wp-config.php');
 
-register_shutdown_function('execute_all_pings');
-//execute_all_pings();
+$now = gmdate('Y-m-d H:i:59');
 
-function execute_all_pings() {
-	global $wpdb;
-	// Do pingbacks
-	while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
-		$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");
-		pingback($ping->post_content, $ping->ID);
-		echo "Pingback: $ping->post_title : $ping->ID<br/>";
-	}
-	// Do Enclosures
-	while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
-		$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';");
-		do_enclose($enclosure->post_content, $enclosure->ID);
-		echo "Enclosure: $enclosure->post_title : $enclosure->ID<br/>";
-	}
-	// Do Trackbacks
-	while ($trackback = $wpdb->get_row("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' AND post_status != 'draft' LIMIT 1")) {
-		echo "Trackback : $trackback->ID<br/>";
-		do_trackbacks($trackback->ID);
-	}
+// Do pingbacks
+while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' AND {$wpdb->postmeta}.meta_value <= '$now' LIMIT 1")) {
+	$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");
+	pingback($ping->post_content, $ping->ID);
+	echo "Pingback: $ping->post_title : $ping->ID<br/>";
 }
 
-_e('Done.');
+// Do Enclosures
+while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
+	$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';");
+	do_enclose($enclosure->post_content, $enclosure->ID);
+	echo "Enclosure: $enclosure->post_title : $enclosure->ID<br/>";
+}
 
+// Do Trackbacks
+while ($trackback = $wpdb->get_row("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' AND post_status != 'draft' ANT post_date_gmt <= '$now' LIMIT 1")) {
+	echo "Trackback : $trackback->ID<br/>";
+	do_trackbacks($trackback->ID);
+}
+
 ?>

