Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Memory resident Object that survive a request?

Posted on 2004-10-27
7
Medium Priority
?
213 Views
Last Modified: 2007-12-19
Well this is a bit theoretical: I want to create an object once and use it in multiple requests, this is the short version.

The long version is: I have an object which loads a lot of data (some mega) into an array, now I realise that loading it on each request is a huge waste of time since the data does not change often. Is it possible to build an object which can be reused (without having to re-initialize it) for more than one request?
0
Comment
Question by:Snyke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 200 total points
ID: 12419242
you can use the serialize and unserialze function of php to store that object into a file
see http://de3.php.net/manual/en/function.serialize.php

To store the object in the memory might be a littel more complicated. Have a look athe the shared memory extension of php (not available on Windows) http://de3.php.net/manual/en/ref.sem.php
0
 
LVL 2

Expert Comment

by:suresh_asp
ID: 12419447
You can also use sessions(overcomes read/write time), which by default serializes and unserializes data.

1. Register your class object using session_register(object)
2. Include your class file ex: YourClass.inc in every php page.

0
 
LVL 3

Expert Comment

by:gnudiff
ID: 12419623

This is one area where PHP differs from application servers like Tomcat, BEA.

PHP does not have application-wide global objects.

Sessions IS a way to simlate that, just remember then that this object will be copied once per each session. :-]
ie. 100 users = 100 sessions = 100 mb of the objects.

I am looking at this prob for some time and have decided to write some SHM-based global object manager; I will probably even put it somewhere under GNU license, but it is not there yet.
0
 
LVL 1

Author Comment

by:Snyke
ID: 12422667
As I see it, the option of storing the stuff in the session is just as good as loading the thing everytime, since sessions are itself stored in files...
0
 
LVL 48

Expert Comment

by:hernst42
ID: 12422750
The advantage of having it in an extra file is, that if you update that file all next request will have that updated object. If it's stored in the session, the old old version may last a long time...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question