Playing with PHPInfo GET PRINT SET PRINT PHP Memory Limit and Max Execution Time

by Hiroshi on January 25, 2013

in Info, Limitations, Tricks

‘Memory Limit’ and PHP Script ‘Max Execution Time’. Both are limitations set by Server, that force a developer to remain conscious about resources consumption by their scripts – and for a good reason. You do not want your server to get overloaded by running scripts and infinite loops causing low memory available for rest of your website to even display pages to regular user. Memory Limit and Max execution Time will restrict a script to run forever and abort it if it is stuck somewhere. This server configuration is necessary. But sometimes we need a bit more resources power to push some important stuff. Here is how to view Memory Limit and Max Execution Time Limit on server and then increase it and review it to confirm that it has increased or not.

PHP info gives all the information about installed PHP on your server:

<?php phpinfo(); ?>

You can choose to select to view selected part of information like this:

<?php phpinfo(INFO_CONFIGURATION); ?>
<?php phpinfo(INFO_MODULES); ?>
<?php phpinfo(INFO_GENERAL); ?>
<?php phpinfo(INFO_VARIABLES); ?>
<?php phpinfo(INFO_LICENSE); ?>

Here it is

<?php
// get memory limit and print it
echo ini_get('memory_limit'); // 90M 
// set new memory limit
ini_set('memory_limit','128M');
echo "<br />";
// print new memory limit to see if it works
echo ini_get('memory_limit'); // 128M 
?>
<?php
// get execution time for running script and print it
echo ini_get('max_execution_time'); // 30
// set new time limit
set_time_limit(100);
echo "<br />";
// get new time limit to see if it works
echo ini_get('max_execution_time'); // 100
 
// unlimited time limit - do not use this
// set_time_limit(0);
?>

If you set these new limits, they will be effective for a running script only.

Related Posts

Previous post:

Next post: