Ciao.
Sto cercando di integrare uno script php con wordpress (come plugin) , questo è lo script:
Codice PHP:
<?php
/*
Plugin Name: checkOnline Status
Version: 0.1
*/
add_action( 'cO_cron_hook', 'CheckRemoteService' );
if( !wp_next_scheduled( 'cO_cron_hook' ) ) {
wp_schedule_event( time(), 'daily', 'cO_cron_hook' );
}
register_deactivation_hook( __FILE__, 'bl_deactivate' );
function bl_deactivate() {
$timestamp = wp_next_scheduled( 'cO_cron_hook' );
wp_unschedule_event($timestamp, 'cO_cron_hook' );
}
function CheckRemoteService($atts) {
extract(shortcode_atts(array(
'url' => 'http://',
'cache' => '600', // 60*10 (10 minutes)
'online' => 'Online', // Custom online msg
'offline' => 'Offline' // Custom online msg
), $atts));
$CachedStatus = 'cstatus_' . $url;
$cachedposts = get_transient($CachedStatus);
if ($cachedposts !== false) {
return $cachedposts;
} else {
// Sometimes its best to change to a custom agent message
// so you know where requests are coming from.
$agent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$url );
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_VERBOSE,false);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_SSLVERSION,3);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode >= 200 && $httpcode < 400) {
return $online;
} else {
return $offline;
}
set_transient($CachedStatus, $return, $cache);
return $return;
}
}
add_shortcode('checkmyurl','CheckRemoteService');
?>
Questo script mi permette di ottenere lo status di un url attraverso l'uso degli shortcodes di wordpress. Ho aggiunto anche la cronologia di wordpress. Il problema è che devo mostrare lo status di 50 siti ma la pagina impiega molto per caricarsi. Io pensavo che con la cronologia l'esecuzione della funzione venisse bloccata ed eseguita una volta sola. Invece lo script viene eseguito ogni volta che visito o ricarico la pagina con gli shotcodes. Praticamente vorrei che venissero mostrati solo i dati aggiornati dalla cronologia. Come posso fare ?
Grazie.