10

我在前端使用DHTMLX 调度程序,在后端使用 DHTMLX 连接器作为我的无线电自动化应用程序的一部分。每次用户编辑日历时,都会对如下所示的文件进行 AJAX 调用:

require_once("dhtmlxScheduler_v4/connector/scheduler_connector.php");
require_once('QDRAconf.php');

$res = mysql_connect($QDRAconf['mysqlHost'], $QDRAconf['mysqlUser'], $QDRAconf['mysqlPass']);
mysql_select_db($QDRAconf['mysqlDb']);

// init the schedulerconnector
$conn = new SchedulerConnector($res);

// render the table
$conn->render_table("events","id","start_date,end_date,text");

这个文件是我的“垫片”,它将前端连接到后端。我想运行另一个 PHP 脚本,将更改写入我的 crontab,但它需要在 DHTMLX 库更新数据库之后发生。麻烦的是,只要 DHTMLX 库认为它已经完成,它就会自动退出:有时它可能不会超过第一require_once('...')行,所以我不能只放在require_once('cronwriter.php');脚本的最后一行。

我对此的解决方案是创建一个带有析构函数的类,该析构函数用最新的更改更新 crontab。由于 php 手册指出,如果调用 exit() 或 die() 函数,析构函数仍将运行,因此我添加了一个带有运行cronwriter.php脚本的析构函数的虚拟类:(我将其添加到文件的开头。)

class ExitCatcher
{
    function __destruct()
    {
        require_once('cronwriter.php');
    }
}
//init the class
$ExitCatcher = new ExitCatcher;

由于某种原因,它不起作用。

4

1 回答 1

2

register_shutdown_function may offer a quick solution; but, you might save yourself some future trouble by inspecting the cause of that library's sporadic process haltings.

A good place to start might be...

  • your browser's JS console for JS errors
  • your JS console's network tab for AJAX errors
  • your server's error logs for PHP errors
于 2014-09-12T16:05:10.990 回答