Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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
如何使用php中的java在linux中监控文件_Java_Php_Linux - Fatal编程技术网

如何使用php中的java在linux中监控文件

如何使用php中的java在linux中监控文件,java,php,linux,Java,Php,Linux,我在linux中有一个程序,当它检测到一个新连接的套接字时,会创建/修改一个文件。它将ip记录在该文件中,并在客户端断开或断开连接时将其删除 在php中,我知道inotify,但它是阻塞和刷新的,不像java。。如何使用java和php实现这一点,以便在linux中监视文件并更新网站,使其知道linux中的文件已被修改 谢谢 e、 php中的g <?php $fd = inotify_init(); $watch_descriptor = inotify_add_watch($fd,

我在linux中有一个程序,当它检测到一个新连接的套接字时,会创建/修改一个文件。它将ip记录在该文件中,并在客户端断开或断开连接时将其删除

在php中,我知道inotify,但它是阻塞和刷新的,不像java。。如何使用java和php实现这一点,以便在linux中监视文件并更新网站,使其知道linux中的文件已被修改

谢谢

e、 php中的g

<?php

$fd = inotify_init();

$watch_descriptor = inotify_add_watch($fd, '/tmp/devfile.txt', IN_MODIFY);

touch('/tmp/devfile.txt');

while(true){
$events = inotify_read($fd);

$contents =file_get_contents('/tmp/devfile.txt');

echo $contents;
}

$read = array($fd);
$write = null;
$except = null;

stream_select($read,$write,$except,0);


stream_set_blocking($fd, 0);

inotify_read($fd); 

$queue_len = inotify_queue_len($fd);

inotify_rm_watch($fd, $watch_descriptor);


fclose($fd);

?>

Java 7支持类似inotify的文件通知。有关教程,请参见


也许您可以找到或编写一个可以从PHP使用的C程序?

我不确定“java和PHP”是什么意思,但如果您正在寻找一种纯java的方式来通知文件的更改,那么您可以使用java.nio.file.Path和WatchService api


它是如何工作的。

谢谢。这是否在不刷新浏览器的情况下工作?。。我是java新手,我需要处理不需要刷新就可以获得新数据的数据。再次感谢。@demic0de-我们在这里谈论的与web浏览器无关(但就我所知,您的php代码也与此无关)。如果您希望将通知从服务器发送到客户端的浏览器,并且不刷新浏览器,请查看WebSocket。“也许您可以找到或编写一个可以从PHP使用的C程序?”---这是什么意思?。。将与php通信的c程序?是的,我做了类似的事情。虽然我并不真正了解PHP的功能。你能从PHP调用C函数吗?如果是这样的话,那就这么做吧。