It happens to the best: some script rockets to the
skyline resulting in an instand system administrator headache because
some folder – typically, sessions – was stuffed with millions of files.
Linux is not quite happy with that, deleting the folder is not an option
and the loyal “rm -rf” command decides to call it a day. To make things
even worse: you want to remove only files of some days ago… what are
the options?
Find is you friend
The Linux “find” command is a possible solution, many will go for:
The
command above will give a list of files older than 3 days and will pass
each found file to the rm command. The rule above has one problem
though: it will take some time, since calling the rm command a million
times is not exactly what you can call efficient.
A better option is:
find /yourmagicmap/* -type f -mtime +3 -delete
This
adds the delete flag to the find command giving it the command to throw
it all away. Do the right thing and pass along your command in a
cronjob if you need to clean out the folder on a regular basis.
The rsync alternative!
rsync
is without doubt one of the most handy commands when it comes to file
operations. Rsync can do any kind of volume sync – as you may know – but
it also provides a way to empty a folder. The example below assumes
you have a folder named /tmp/empty/ which contains no files, and a
folder /tmp/session/ that contains too much crap. The rule below allows
you to remove those files:
rsync -a --delete /tmp/empty /tmp/session/
Which is the fastest?
rm: deleting millions of file is a no-can-do!
find -exec: an option, but slower!
find -delete: fast and easy way to remove loads of files.
Test Server: Digital Ocean Ubuntu 16.04.1 x64 2gb / 2CPU droplet.
Test Software: PHP 7.1.0, Apache 2.4.18
I used a minimal installation of PHP and Apache with no additional configurations or sever settings changed.
Overview
The
benchmark tool kit executes a simple “hello world”, it does this with
the frameworks minimal settings, no database, no debugging and if
possible, no template engine.
Out
of the 6 frameworks tested Codeigniter 3 produced the most requests per
second and the least memory usage. Zend Framework 2.5 produced the
least requests per second and Laravel 5.3 produced the most memory
usage.
No framework: 7,094 requests per second, .34M memory. Codeigniter 3: 2,245 requests per second, .38M memory. Lumen5.3: 1,543 requests per second, .63M memory. Fuel1.8: 1,033 requests per second, .60M memory. Symfony3.0: 551 requests per second, 1.52M memory. Laravel5.3: 331 requests per second, 1.53M memory Zend2.5: 291 requests per second, 1.34M memory
Compared
to PHP 7.0 we see close to 2,000 more requests per second with no
framework along with a considerable increase for Codeigniter 3.
Requests Per Second
Codeigiter produces the most requests per seconds. Lumen and Fuel perform decently well but the rest of the frameworks produced very low results.
Memory
Codeigniter consumes the least amount of memory. Lumen and Fuel come in under 1M but Laravel, Symfony and Zend consume more then double the memory of the other frameworks.
Execution Time
Laravel and Zend take the longest time to execute with Symfony close behind. Fuel and Lumen are the fastest and Codeigniter has fallen to 3rd place.
Included Files
Codeigniter, Lumen and Fuel remain the top 3 frameworks that include the least files. Symfony is loading less files while Laravel has appeared to doubled the amount of included files.
PHP 7.0 Comparison
PHP 7.0
PHP 7.1
We see most frameworks have improved requests per second. Laravel has moved up one spot and all frameworks serve more requests then before.
Almost all the frameworks utilize less memory. In the case of Laravel and Symfony we see memory usage now under 2M.
I don’t think having a variable of 2 forms is a good idea:
<?php$items=null;// same as "private $items;" in a classechosprintf('There is %d items',count($items));// error Warning: count(): Parameter must be an array or an object that implements Countable
But in case of that smelly (3rd party) code, there is a help: