Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP objects that stay in memory

Tags:

php

I recall reading on php.net (although unfortunately can't seem to find the page) that the PHP interpreter can run in different ways - most commonly, every time a page is requested, an instance of the PHP interpreter is created, runs its course, and then is destroyed, along with all the memory associated with that particular page call. Apparently, it is also possible to allow all the memory to linger, so that it can be used again in future page calls; as I understood it, essentially allowing multiple different PHP scripts to access and modify the same objects, without losing them after the script is complete.

Or at least, so I remember. Is there any truth to this? If so, how would I set it up?

like image 704
Monchoman45 Avatar asked Apr 19 '12 21:04

Monchoman45


People also ask

How are variables stored in PHP memory?

It's RAM based storage engine. APC APC - PHP manual apc code cache allows store variables. If you don't want any extensions you could store your data into file (serialize, or xml format), and it will be persistent data. Slower then memory storage.

What are the different objects in PHP?

Primary (scalar) variables, arrays and other objects can be cast to object data type using casting operator. PHP provides stdClass as a generic empty class which is useful for adding properties dynamically and casting.

What are PHP objects explain with example?

Objects are real-world entities. Objects are defined from classes in Object-Oriented Programming like PHP. When a class is defined, we can create many objects out of the class. Example Class Car is defined, then Mercedes, BMW, Skoda are all objects of the Class Car. A class is a blueprint of an object.


1 Answers

php doesn't work that way. its about run and forget.

you can save data between requests using userland shared memory extensions, for example: apc, xcache, memcached, etc.

or by using the session data array after calling session_start

$_SESSION

don't think of php scripts like a java application in e.g. tomcat. standard php was not designed for that use case. php compiler works on-the-fly.

like image 182
Hajo Avatar answered Oct 11 '22 22:10

Hajo