Php Curl在wordpress计划事件/cron中不工作
我使用以下代码创建了一个wordpress计划事件Php Curl在wordpress计划事件/cron中不工作,php,wordpress,curl,cron,Php,Wordpress,Curl,Cron,我使用以下代码创建了一个wordpress计划事件 add_filter('cron_schedules','cliv_cron_add_syncdays'); function cliv_cron_add_syncdays($schedules){ $schedules['syncdays'] = array( 'interval' => 15, 'display'=> 'Sync Days' ); return $schedules;
add_filter('cron_schedules','cliv_cron_add_syncdays');
function cliv_cron_add_syncdays($schedules){
$schedules['syncdays'] = array(
'interval' => 15,
'display'=> 'Sync Days'
);
return $schedules;
}
add_action('init','cliv_create_recurring_schedule');
add_action('cron_action','cron_function');
function cron_function(){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("DATA SYNC"));
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, true);
mail("mymail@mail.com", "wp Cron test", $response);
}
function cliv_create_recurring_schedule(){
if(!wp_next_scheduled('cron_action'))
wp_schedule_event (time(), 'syncdays', 'cron_action');
}
如果我直接调用cron_函数(),一切都正常。
但是,如果该函数是从cron运行的,则会收到邮件,但没有数据。(我想在这种情况下curl不起作用)
伙计们。请帮我一个忙。在您的实际代码中是否定义了$url变量?如果是,在哪里?