私は、ブラウザタブを開いて閉じないと、wp_schedule関数がバックグラウンドでajaxのようなcronを実行することを理解しています。だから、なぜ私の機能はそれを働かせることができませんでしたか?なぜWordPressのwp_schedule関数が機能しないのですか?
私のcoumputer時間= my wordpress設定時間= GMT時間をphp.iniに変更しました。しかしそれはまだ動作しません、私のコードは以下のとおりです。私はそれをwordpressプラグインの中に入れました。だから私は何をしなければならないのですか?
class CronTest {
function __construct() {
add_action('init', array ($this, 'g_order_sync'));
add_action('ga_order_syn', array ($this, 'sync_order'));
}
// init
public function g_order_sync() {
try{
if (! wp_next_scheduled('ga_order_syn')) {
wp_schedule_event( time() + 10, null, 'ga_order_syn');
}
}
catch(Exception $ex)
{
echo "<p>The error: " . $e->getMessage() . "</p>"; //display error
}
}
// cron job
public function sync_order() {
$content = time() . ": some text here";
$this->_write_content ($content);
}
// write content
private function _write_content($content = '') {
$path = $_SERVER[ 'DOCUMENT_ROOT' ] . "/myText.txt";
if(is_writable($path)) {
$original = file_get_contents($path);
$original .= PHP_EOL . $content;
$fp = fopen($path, "wb");
fwrite($fp, $original);
fclose($fp);
} else {
// log error here
}
}
}
// must initialize the cron class
$cron_test = new CronTest();
私のコードには何が間違っていますか? –
私は答えを広げました。 –
ねえ、あなたは成功した。しかし、もし私が削除した場合、私のコードはちょうどwok:if(!wp_next_scheduled( 'wpwhosonline_update')){。しかし、私はそれを削除しない場合、それは重複した複数の時間を実行します。 –