สอบถามการใช้ cron ใน phpBB ครับ
Moderator: mindphp, ผู้ดูแลกระดาน
-
- PHP VIP Members
- โพสต์: 3751
- ลงทะเบียนเมื่อ: 06/06/2022 9:43 am
สอบถามการใช้ cron ใน phpBB ครับ
ผลอยาก set เวลาทำงานของ phpBB ต้องทำอย่างไรบ้างครับ เช่น ต้องการให้ทำงาน ทุก ๆ 3 ชม หรือ 6 ชม ต่อวัน
- eange08
- PHP VIP Members
- โพสต์: 16441
- ลงทะเบียนเมื่อ: 22/12/2020 10:09 am
Re: สอบถามการใช้ cron ใน phpBB ครับ
ลองดูการเขียน cron เพื่อให้รันทำงาน เรากำหนดช่วงเวลาทำงานตามความถี่ที่เรากำหนดตามค่า config
viewtopic.php?t=88326
viewtopic.php?t=88326
-
- PHP VIP Members
- โพสต์: 3751
- ลงทะเบียนเมื่อ: 06/06/2022 9:43 am
Re: สอบถามการใช้ cron ใน phpBB ครับ
สอบถามเพิ่มเติมครับeange08 เขียน: ↑13/09/2022 10:58 am ลองดูการเขียน cron เพื่อให้รันทำงาน เรากำหนดช่วงเวลาทำงานตามความถี่ที่เรากำหนดตามค่า config
viewtopic.php?t=88326
การ debug ค่า เราจะ debug ยังไงครับของ
หรือจะรู้ได้ไงครับว่าเข้ามาทำงานอยู่
โค้ด: เลือกทั้งหมด
<?php
/**
*
* An extension for the phpBB Forum Software package.
*
* @copyright (c) 2020, Gregor Morrill, https://stevens-stevens.com
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace mindphp\m_dashboard\cron\task;
class time_dashboard_data extends \phpbb\cron\task\base
{
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\log\log */
protected $log;
/**
* Constructor
*
* @param \phpbb\config\config $config Config object
*/
public function __construct(\phpbb\user $user, \phpbb\config\config $config, \phpbb\config\db_text $config_text, \phpbb\db\driver\driver_interface $db, \phpbb\log\log $log, $table_prefix, $phpbb_root_path, $php_ext)
{
$this->user = $user;
$this->config = $config;
$this->config_text = $config_text;
$this->db = $db;
$this->log = $log;
$this->table_prefix = $table_prefix;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
/**
* Runs this cron task.
*
* @return void
*/
public function run() //ส่วนนี้ใส่การทำงานของ cron เราว่าจะให้ทำอะไร เช่น เพิ่ม - แก้ไข - ลบ ตามที่เราต้องการ และถ้าจะให้รันรอบต่อไปให้เราบันทึกวันเวลาล่าสุดเอาไว้ (ลงท้าย _gc)
{
// echo "test";
// exit();
$sql = "INSERT INTO `test_001` (`id`, `test`) VALUES (NULL, '1');";
$this->db->sql_query($sql);
// $this->example1();
$this->log->add('admin', 2, '127.0.0.1', 'Update example sucess - ' . time());
// $today_run_set = '';
// $this->config->set('time_dashboard_data_last_gc', $today_run_set, true);
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* For example, a cron task that prunes forums can only run when
* forum pruning is enabled.
*
* @return bool
*/
public function is_runnable() //ช็คว่าถึงเวลาแล้วเริ่มรันได้เลย
{
return true;
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* @return bool
*/
public function should_run() //ส่วนที่เช็คว่าใกล้ถึงเวลารันตามที่คำนวณวันเวลาถัดไปที่จะรัน เพื่อเข้าคิวรอรัน
{
return $this->config['time_dashboard_data_last_gc'] < time() - $this->config['time_dashboard_data_gc'];
}
// public function example1() //สามารถเขียน method เพิ่มเติมได้
// {
// $this->log->add('admin', 2, '127.0.0.1', 'Update example1' . time());
// }
}
- eange08
- PHP VIP Members
- โพสต์: 16441
- ลงทะเบียนเมื่อ: 22/12/2020 10:09 am
Re: สอบถามการใช้ cron ใน phpBB ครับ
เช็คจาก log ที่เราแทรกการทำงานเอาไว้ก็ได้ค่ะflook เขียน: ↑13/09/2022 3:19 pmสอบถามเพิ่มเติมครับeange08 เขียน: ↑13/09/2022 10:58 am ลองดูการเขียน cron เพื่อให้รันทำงาน เรากำหนดช่วงเวลาทำงานตามความถี่ที่เรากำหนดตามค่า config
viewtopic.php?t=88326
การ debug ค่า เราจะ debug ยังไงครับของ
หรือจะรู้ได้ไงครับว่าเข้ามาทำงานอยู่โค้ด: เลือกทั้งหมด
<?php /** * * An extension for the phpBB Forum Software package. * * @copyright (c) 2020, Gregor Morrill, https://stevens-stevens.com * @license GNU General Public License, version 2 (GPL-2.0) * */ namespace mindphp\m_dashboard\cron\task; class time_dashboard_data extends \phpbb\cron\task\base { /** @var \phpbb\config\config */ protected $config; /** @var \phpbb\log\log */ protected $log; /** * Constructor * * @param \phpbb\config\config $config Config object */ public function __construct(\phpbb\user $user, \phpbb\config\config $config, \phpbb\config\db_text $config_text, \phpbb\db\driver\driver_interface $db, \phpbb\log\log $log, $table_prefix, $phpbb_root_path, $php_ext) { $this->user = $user; $this->config = $config; $this->config_text = $config_text; $this->db = $db; $this->log = $log; $this->table_prefix = $table_prefix; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; } /** * Runs this cron task. * * @return void */ public function run() //ส่วนนี้ใส่การทำงานของ cron เราว่าจะให้ทำอะไร เช่น เพิ่ม - แก้ไข - ลบ ตามที่เราต้องการ และถ้าจะให้รันรอบต่อไปให้เราบันทึกวันเวลาล่าสุดเอาไว้ (ลงท้าย _gc) { // echo "test"; // exit(); $sql = "INSERT INTO `test_001` (`id`, `test`) VALUES (NULL, '1');"; $this->db->sql_query($sql); // $this->example1(); $this->log->add('admin', 2, '127.0.0.1', 'Update example sucess - ' . time()); // $today_run_set = ''; // $this->config->set('time_dashboard_data_last_gc', $today_run_set, true); } /** * Returns whether this cron task can run, given current board configuration. * * For example, a cron task that prunes forums can only run when * forum pruning is enabled. * * @return bool */ public function is_runnable() //ช็คว่าถึงเวลาแล้วเริ่มรันได้เลย { return true; } /** * Returns whether this cron task should run now, because enough time * has passed since it was last run. * * @return bool */ public function should_run() //ส่วนที่เช็คว่าใกล้ถึงเวลารันตามที่คำนวณวันเวลาถัดไปที่จะรัน เพื่อเข้าคิวรอรัน { return $this->config['time_dashboard_data_last_gc'] < time() - $this->config['time_dashboard_data_gc']; } // public function example1() //สามารถเขียน method เพิ่มเติมได้ // { // $this->log->add('admin', 2, '127.0.0.1', 'Update example1' . time()); // } }
โค้ด: เลือกทั้งหมด
$this->log->add('admin', 2, '127.0.0.1', 'Update example sucess - ' . time());
- mindphp
- ผู้ดูแลระบบ MindPHP
- โพสต์: 41410
- ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
- ติดต่อ:
Re: สอบถามการใช้ cron ใน phpBB ครับ
ได้คำตอบที่สามารถนำไปใช้งานได้หรือยังครับ
ไม่เข้าใจตรงไหนบ้าง
ไม่เข้าใจตรงไหนบ้าง
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
-
- PHP VIP Members
- โพสต์: 3751
- ลงทะเบียนเมื่อ: 06/06/2022 9:43 am
Re: สอบถามการใช้ cron ใน phpBB ครับ
ไม่เข้าใจในาส่วนของ function นี้ครับ มีไว้ทำอะไรeange08 เขียน: ↑13/09/2022 10:58 am ลองดูการเขียน cron เพื่อให้รันทำงาน เรากำหนดช่วงเวลาทำงานตามความถี่ที่เรากำหนดตามค่า config
viewtopic.php?t=88326
โค้ด: เลือกทั้งหมด
public function effectively_installed() {
return isset($this->config['m_example_version']) && version_compare($this->config['m_example'], '1.0.0', '>=');
}
-
- Similar Topics
- ตอบกลับ
- แสดง
- โพสต์ล่าสุด
-
- 2 ตอบกลับ
- 1240 แสดง
-
โพสต์ล่าสุด โดย flook
28/12/2022 3:43 pm
-
-
โพสต์ใหม่ สอบถามการใช้ core.viewtopic_modify_post_row phpBB
โดย flook » 25/07/2022 10:42 am » ใน Programming - PHP - 4 ตอบกลับ
- 790 แสดง
-
โพสต์ล่าสุด โดย mindphp
30/07/2022 11:51 am
-
-
-
โพสต์ใหม่ สอบถามเรื่อง Cron Status ของ phpBB
โดย flook » 26/09/2023 4:05 pm » ใน สอบถามปัญหาการใช้ phpBB3, SMF, Joomla, Wordpress, CMS, CRM - 2 ตอบกลับ
- 993 แสดง
-
โพสต์ล่าสุด โดย flook
27/09/2023 9:45 am
-
-
-
โพสต์ใหม่ สอบถามส่วนของ cron ใน phpbb ครับ
โดย anawatj » 11/09/2023 2:47 pm » ใน สอบถามปัญหาการใช้ phpBB3, SMF, Joomla, Wordpress, CMS, CRM - 2 ตอบกลับ
- 594 แสดง
-
โพสต์ล่าสุด โดย anawatj
12/09/2023 12:14 pm
-
-
-
โพสต์ใหม่ อยากทราบวิธีการตั้งค่า php เพื่อที่จะให้ cron ใน phpbb สามารถทำงานได้
โดย Ittichai_chupol » 19/05/2020 10:16 am » ใน Programming - PHP - 0 ตอบกลับ
- 716 แสดง
-
โพสต์ล่าสุด โดย Ittichai_chupol
19/05/2020 10:16 am
-
-
-
โพสต์ใหม่ อยากจะดู Cron Status บน phpBB 3.3.4 อย่างไรบ้างค่ะ
โดย eange08 » 15/09/2021 3:20 pm » ใน สอบถามปัญหาการใช้ phpBB3, SMF, Joomla, Wordpress, CMS, CRM - 1 ตอบกลับ
- 1281 แสดง
-
โพสต์ล่าสุด โดย mindphp
15/09/2021 3:33 pm
-
-
- 2 ตอบกลับ
- 831 แสดง
-
โพสต์ล่าสุด โดย eange08
13/11/2023 12:53 pm
ผู้ใช้งานขณะนี้
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 104