Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#不';t检测用PHP编辑的文本文件_C#_Php_Linux_Text Files_Tapi - Fatal编程技术网

C#不';t检测用PHP编辑的文本文件

C#不';t检测用PHP编辑的文本文件,c#,php,linux,text-files,tapi,C#,Php,Linux,Text Files,Tapi,我在Linux服务器上有一个PHP网站。我在网站上的电话号码旁边做了一个按钮,在服务器上用这个号码写一个文本文件。下面的代码可以工作 $file = './gebruikers/'.$naam.'/nummer.txt'; $write = $_POST['num']; file_put_contents($file, $write); 现在我用TAPI3编写了一个C#应用程序来调用该文本文件中的号码。 我使用FileSystemWatcher(watcher)来检查php保存文本文件的文件夹

我在Linux服务器上有一个PHP网站。我在网站上的电话号码旁边做了一个按钮,在服务器上用这个号码写一个文本文件。下面的代码可以工作

$file = './gebruikers/'.$naam.'/nummer.txt';
$write = $_POST['num'];
file_put_contents($file, $write);
现在我用TAPI3编写了一个C#应用程序来调用该文本文件中的号码。 我使用FileSystemWatcher(watcher)来检查php保存文本文件的文件夹,这样每当文件更新时它都会进行调用

下面的代码检查选中的用户,以便监视该用户文件夹中的文本文件

    private void cbGebruikers_SelectedIndexChanged(object sender, EventArgs e)
    {    
        if(cbGebruikers.Text != "")
        {
            comboBox1.Enabled = true;
            button6.Enabled = true;
            lblGebruiker.Visible = false;
            lblTelefoon.Visible = true;
        }

        path = @"\\192.168.1.9\SB Alarm programma\web-sb\gebruikers\" + cbGebruikers.Text;
        watcher.Path = path;
        watcher.NotifyFilter = NotifyFilters.LastAccess;
        watcher.Filter = "*.*";
        watcher.Changed += new FileSystemEventHandler(OnChanged);
        watcher.EnableRaisingEvents = true;

        lbltest.Text = watcher.Path.ToString();
    }
当文本文件更改时,将执行以下代码

    private void OnChanged(object sender, FileSystemEventArgs e)
    {
        try
        {
            watcher.EnableRaisingEvents = false;

            telnummer = File.ReadAllText(path + "/nummer.txt");


            nummer = "0" + telnummer;


            this.Invoke((MethodInvoker)delegate
            {
                txtNummer.Text = nummer;
                MakeCall(nummer);
            });
        }
        finally
        {
            watcher.EnableRaisingEvents = true;
        }
    }
如果我在我的电脑或另一台有权访问该文件夹的电脑上更改文件夹中的文本文件,应用程序就会调用此代码。 但是,如果PHP更改文本文件,则不会发生任何事情,但最后修改的日期会更新


有人对此有经验吗?

您能否尝试将
NotifyFilter
更改为
NotifyFilters.LastWrite
?或者,如果要同时监视这两种情况,请更改为
NotifyFilters.LastWrite | NotifyFilters.LastAccess


另外,如果文件是由PHP创建的,您可能希望向
watcher.created

添加一个事件处理程序。这看起来像是在跨平台体系结构中使用FileSystemWatcher的问题。FileSystemWatcher的工作原理是打开与远程服务器的连接,远程服务器的责任是在指定文件发生更改时做出响应。Windows平台使用Win32 ReadDirectoryChanges(),而Linux机箱使用Inotify API。由于这两个API之间没有接口,Linux box无法响应FileSystemWatcher

相关链接

谢谢您的回复!我已经试过LastWrite了,但它也做了同样的事情。但我会在通话后尝试创建并删除该文件。谢谢您的回复!我可能会离开FileSystemWatcher,用计时器每隔x秒检查一次文本文件。没问题!这在这里也更简单、更容易调试。