Skip to Content
Mastering PHP 7
book

Mastering PHP 7

by Branko Ajzele
June 2017
Intermediate to advanced
536 pages
9h 49m
English
Packt Publishing
Content preview from Mastering PHP 7

Memory management

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning PHP 7

Learning PHP 7

Antonio L Zapata (GBP)
Upgrading to PHP 5

Upgrading to PHP 5

Adam Trachtenberg

Publisher Resources

ISBN: 9781785882814Supplemental Content