Php offers c type functions to handle files. But php also provides some more functions which are simple and faster than all c type functions like fopen() fread() file() etc...
Example 1
readfile() function can be used directly to simply read the file and output its contents to standard output. We can use this function instead of c type functions for better performance.
Example 2
// classic old method
$content = implode("\n", file("filename.txt"));
// it load complete file in memory and large files can make server over load.
// New php 4.3.0 method
$content = file_get_contents("filename.txt");
// in this we can specify the limit to load the file. So at least you have control over memory.
New function in php5.0.0
file_put_contents('file_path','Data to write',MODE);
We can write in to any file in one shot. no need to create any file handle separate.
simple file handling functions faster than ctype functions
Posted by
php helper
at
6:39 AM
Labels: file operations, php
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment
Post your helpful suggestions on this...