【发布时间】:2016-04-20 21:18:50
【问题描述】:
我想知道是否可以在 PHP 文件锁中使用 simplexml 从 xml 文件中打开、读取和写入。如果不可能,如何同时使用简单的xml实现锁定文件和读/写?
例如:
$file = fopen('text.xml', 'r+');
flock($file, LOCK_EX);
if (file_exists('test.xml'))
{
$xml = simplexml_load_file('test.xml');
//Retrieve xml element,
//Save XML element back to test.xml here
print_r($xml);
}
else
{
exit('Failed to open test.xml.');
}
flock($file, LOCK_UN);
【问题讨论】:
标签: php xml simplexml file-locking flock