我知道file_put_contents()可以很容易地将数据附加到PHP中的文件中.我想尝试将PHP" 线程 "用于file_put_contents()来自不同PHP线程的相同日志文件.从不同的PHP线程在同一文件上运行file_put_contents()是否存在风险,或者如果文件被锁定或被另一个线程访问,这些线程是否会高兴地阻塞?
Nea*_*eal 24
正如它在手册页上所说的那样(你给了一个链接!):
// Write the contents to the file, 
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same time
file_put_contents($file, $person, FILE_APPEND | LOCK_EX);
使用该LOCK_EX标志可防止双重写入