Ticket #7068: 7068_cron_part2.diff
File 7068_cron_part2.diff, 2.8 KB (added by , 17 years ago) |
---|
-
C:/xampp/htdocs/wordpress_trunk/wp-includes/cron.php
71 71 return false; 72 72 } 73 73 74 function spawn_cron() { 74 function spawn_cron( $local_time ) { 75 global $current_blog; 76 77 /* 78 * do not even start the cron if local server timer has drifted 79 * such as due to power failure, or misconfiguration 80 */ 81 $timer_accurate = check_server_timer( $local_time ); 82 if ( !$timer_accurate ) 83 return; 84 85 //sanity check 75 86 $crons = _get_cron_array(); 76 77 87 if ( !is_array($crons) ) 78 88 return; 79 89 80 90 $keys = array_keys( $crons ); 81 if ( array_shift( $keys ) > time() ) 91 $timestamp = $keys[0]; 92 if ( $timestamp > $local_time ) 82 93 return; 83 94 95 /* 96 * multiple processes on multiple web servers can run this code concurrently 97 * try to make this as atomic as possible by setting doing_cron switch 98 */ 99 $flag = get_option('doing_cron'); 100 101 // clean up potential invalid value resulted from various system chaos 102 if ( $flag != 0 ) { 103 if ( $flag > $local_time + 10*60 || $flag < $local_time - 10*60 ) { 104 update_option('doing_cron', 0); 105 $flag = 0; 106 } 107 } 108 109 //don't run if another process is currently running it 110 if ( $flag > $local_time ) 111 return; 112 113 update_option( 'doing_cron', $local_time + 30 ); 114 115 //proceed to run cron 84 116 $cron_url = get_option( 'siteurl' ) . '/wp-cron.php'; 85 117 $parts = parse_url( $cron_url ); 86 118 … … 94 126 } 95 127 } else { 96 128 $port = isset($parts['port']) ? $parts['port'] : 80; 97 $argyle = @ fsockopen( $ parts['host'], $port, $errno, $errstr, 0.01 );129 $argyle = @ fsockopen( $_SERVER['SERVER_ADDR'], $port, $errno, $errstr, 0.01 ); 98 130 } 99 131 100 132 if ( $argyle ) … … 105 137 } 106 138 107 139 function wp_cron() { 140 108 141 // Prevent infinite loops caused by lack of wp-cron.php 109 142 if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false ) 110 143 return; … … 117 150 $keys = array_keys( $crons ); 118 151 if ( isset($keys[0]) && $keys[0] > time() ) 119 152 return; 120 153 154 $local_time = time(); 121 155 $schedules = wp_get_schedules(); 122 156 foreach ( $crons as $timestamp => $cronhooks ) { 123 if ( $timestamp > time()) break;157 if ( $timestamp > $local_time ) break; 124 158 foreach ( $cronhooks as $hook => $args ) { 125 159 if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) ) 126 160 continue; 127 spawn_cron( );161 spawn_cron( $local_time ); 128 162 break 2; 129 163 } 130 164 } … … 190 224 return $new_cron; 191 225 } 192 226 227 // stub for checking server timer accuracy, using outside standard time sources 228 function check_server_timer( $local_time ) { 229 return true; 230 } 231 193 232 ?>