- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
flock() function in PHP
The flock() function locks or releases a file. The function returns TRUE on success and FALSE on failure.
Syntax
flock(file_pointer, operation, block)
Parameters
file_pointer − A file pointer for open file to lock or release.
operation − Specifies the lock to use:
- LOCK_SH - Shared lock (reader)
- LOCK_EX - Exclusive lock (writer)
- LOCK_UN - Release a shared or exclusive lock
block − Set to 1 if the lock would block
Return
The flock() function returns.
- TRUE on success
- FALSE on failure
Example
<?php $file_pointer = fopen("new.txt","w+"); // shared lock if (flock($file_pointer,LOCK_SH)) { fwrite($file_pointer,"Some content"); flock($file_pointer,LOCK_UN); } else { echo "Locking of file shows an error!"; } fclose($file_pointer); ?>
Output
TRUE
Advertisements