June 2017
Intermediate to advanced
536 pages
9h 49m
English
Quite often, PHP developers need to deal with a large amount of data. While large is a relative term, memory is not. Certain combinations of functions and language constructs, when used irresponsibly, can clog our server memory in a matter of seconds.
Probably the most notorious function is file_get_contents(). This easy-to-use function literally grabs the content of an entire file and puts it into memory. To better understand the issue, let's take a look at the following example:
<?php$content = file_get_contents('users.csv');$lines = explode("\r\n", $content);foreach ($lines as $line) { $user = str_getcsv($line); // Do something with data from $user...}
While this code is perfectly valid and working, it is a potential ...