PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 28th, 2004, 08:32 PM
yanivn yanivn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 4 yanivn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question php design and efficiency issues

Howdy

My background is unix C++ programming. I started web ( asp :-( ) only 6 moth ago.
My NT/IIS/ASP website needs to find a more reliable form of existance if you get what I mean ... therefore i'm switching to the reliable configuration Linux/Apache/PHP.
The need to convert my code from ASP to PHP gave a little hope of coding the right way, when you can use your machines resources and they won't crash or get stuck.
This mainly bothers me because my application needs session tracking including gathering new data from each new page (input from form, time in page etc). when the user leaves my site, i need to make sure all the set of that sessions data is stored to the DB.

When running a PC machine with WIN server of some sort, the common idea is DON'T TOUCH SESSION PARAMS. Why ? In windows the whole threading and memory maintenance looks like a 3rd world country and more. I need to understand if when running a PHP code on linux machine, resource handling is done better, so I'll give you my options.
There are few ways to gather data the way I understand.

First one would be what I did with ASP, storing most of the info @ client side and when the session is over to save them. This is done when the main HTML page has an inner frame within, thats where the changing content is. There are JS params on the main HTML page(or a handling JS class), and on every reload of the inner frame, the params from the inner frame is saved in the main page. when the session dies , JS on_unload function sends all the data to the server as inner form data without replying to client (is that CGI ?....). This way i contact the DB only when the session ends, and still can maintain the data from the session. I can still keep a little general info (like id) on each session using cookies and/or $_SESSION.

Second option would be the exact opposite, to store new data @ server side in DB, EVERY TIME a new page is loaded for the current session. That means I have to establish conection with DB and kill it at each page loads. is liux process like unix, and opening connection is no hussle ? just tapping to the resource ?

Third option is to build a handler PHP class to run server side. This class would be either a singelton that will save all data from all sessions in defferent containers, or an instance for each session with a ceperate container. When a session ends, the data would be dumped from the container to the DB. I can init a $_SESSION to hold that class or to use global params. Question here - how efficient (or otherwise) would it be to store and access every time, the $_SESSION params. If the session handling is done better than on WIN stations, I guess this would be the most reliable, portable, well coded way. [p.s. can i init a $_SESSION param with a PHP object of my creation ? again, big problem in ASP... ]

The main issue here is can i go back to my unix days knowing that accesing system resources will not crash my machine, i just have to use them smart ? If I know that on EACH page load from server i can write to a file or DB without feeling sorry for my machine knowing it would be able to handle threading the calls, I can start programming the right way.

Thank you very much,

Yaniv

Reply With Quote
  #2  
Old March 28th, 2004, 10:36 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
I don't think you fully understand how to use sessions. ASPs session handling ability is almost identical to PHPs. Storing session data using JS is an extrememly bad idea. Not only will it not work if the client has JS disabled, but it means that the client then has full access to any data you store on them... i.e. no security.

Using sessions correctly means that you would store the data in either a session object on the server side, or store just the session id in the session object, and store the data in a DB. The theory is the same for almost any server-side scripting language.

What exactly are the issues you are experiencing using ASP to handle your sessions?
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old March 29th, 2004, 01:25 PM
yanivn yanivn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 4 yanivn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post hello stumpy

and thank you for the response.
First let me fix someting in what you said. Of course session HANDLING an idea is done the same in PHP and ASP, but calling it "the same" would be to compare windows resources and thread handling to a unix/linux system.
Ofcourse one can use session params in ASP, but i've checked the memory, and run time, and checked in million places - They all say it's good practice NOT to touch session params on windows machine, too much server overwork.
But thats not the deal here .... so why waste time ?...
You said it's bad practice to do data storing client side since the client can alter it, and client with no JS is no good. My start point is browser JS enabled, how many sides can you tell me that work without that ? As for the client altering data, I can see what you mean, but if the only stored data is forms data and time in page, i'm not really worried. BUT - i see your point.
Now for the solution - you say there is no problem that I load all the data to the $_SESSION as to machine resources ? I read that storing to DB on EACH page load in very bad for server resources even on Linux so I'm left with the session params solution.
So - what I do is build a PHP handler class and create an instance for every session.
Tel me plz, will file accessing on each session start for logging or whatever will not overburden the server ? would you save one global parameter with open connection to file, or open/close every time ?

Thank you

Reply With Quote
  #4  
Old March 29th, 2004, 02:58 PM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
global params

Now. I havnt looked deeply inte session classes and so forth. But i belive, that there has been posted (in top of forum) a description of hov the session class works. Is it not possible to look throug that ?!...

and as i understand it, the session, if global, does not need to be accesed each time the page loads. And will be reset efter browser session ends. As the browser is using its own session. No matter what kind. And what serverside, they can be used the same.

- Pheifel

Reply With Quote
  #5  
Old March 29th, 2004, 07:24 PM
yanivn yanivn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 4 yanivn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yes i understood .....

and i know perfectly how it work in design.
my question was is it EFFICIENT to access session params on each page load, in term of SERVER CPU usage.
On windows it is inefficient and BAD practice to load session param with a container of 30 strings.
However, I believe that Linux is above those petty problems.

I just need someone to say "yes" this is the effiient way .... in CPU usage terms" (and would be eternally gratefull if they could supply some reading materialon the subject)

no point in yelling at new comer "go read the threads" and look in the "search".
some newbees do thats, the answer wasn't there ...

anyway thanx a lot

Reply With Quote
  #6  
Old March 29th, 2004, 07:32 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
There is nothing wrong with loading an ASP Session object with 30 strings or arrays. That is what it they are designed for. You can store as much data as you like, but obviously you must keep in mind the amount of RAM you have available. I'm not sure where you are getting your information from that says there is a problem with ASP sessions... you mentioned CPU - that has nothing to do with sessions. Sessions use memory to store their data. Doing silly things like storing connection objects, etc in sessions is bad practice, and well documented. They are not designed for that.

What is it exactly that you are attempting to do?

Good article on the ASP session and application object: http://www.sitepoint.com/article/as...-applications/1

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > php design and efficiency issues


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway