Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a global variable accessible throughout the application

I developed a PHP page with global variable like this;

global $amty_imgCache; $amty_imgCache = array();
$GLOBALS["amty_imgCache"]=$amty_imgCache;

This page has functions to add/delete entries to/from this array.

I called a function on antother PHP page to display its count and to put some elements into this global array this way;

Count <?php echo amty_getImageCacheCount(); ?>
<?php amty_putIntoImageCache(100,0); ?>
Count <?php echo amty_getImageCacheCount(); ?>

But on every refresh first it displays count 0 then 1.

How can I persist values of global variable across entire application.

like image 761
Amit Kumar Gupta Avatar asked Jan 21 '12 11:01

Amit Kumar Gupta


1 Answers

Use APC or memcache to store such values. You can not only access these values from any page but can also access from any server.

like image 139
Pushpendra Singh Thakur Avatar answered Sep 30 '22 19:09

Pushpendra Singh Thakur