Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How do you cache lists?
Old 09-12-2007, 04:35 AM How do you cache lists?
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Does PHP have a concept like a hash-table for in memory lookups? Can you store a single copy at the application level, so it's not bound to sessions? How difficult is it to raise and consume events across different classes or objects?

I'm thinking about a new server-based project, and Apache is a lot more common than IIS. A little cheaper, too, if you're having it hosted. So I'm wondering if PHP is well suited?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
 
Register now for full access!
Old 09-12-2007, 06:40 AM Re: How do you cache lists?
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Just use an array for in memory lookups. There are no built in collection classes, so if you need keys that are non-strings or non-integers then you'll need to build it yourself.

Out of the box PHP provides no way to share data in memory between requests. You need some sort of PHP accelerator like APC or XCache.

As for events... Again, PHP provides no built-in functionality for this. The amount of built-in classes is very small. There are thousands of functions that do all sorts of things, but there aren't many actual library-like classes.

Instead, PHP has PEAR and PECL. The thought being that the developer will extend PHP with extensions from PECL or use libs from PEAR for whatever functionality he needs.

Anyway, I believe there is a PEAR package that offers some of the features you might find in other languages 'Observable'-type classes.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 09-12-2007, 09:53 PM Re: How do you cache lists?
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Hmmm. Sounds like there's a pretty steep learning curve. I might be better off with a language I already know...

But it sounds like you can use strings instead of integers to index arrays in PHP? How does that work? I know you could write a function to loop through the array until it finds a match, but is there a better method, out of the box?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 09-13-2007, 01:10 AM Re: How do you cache lists?
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Quote:
Hmmm. Sounds like there's a pretty steep learning curve. I might be better off with a language I already know...
It depends. If you are used to the "Java way" for example, it might be a bit of a change to do it the "PHP way". In PHP things are usually a bit simpler. In Java for example you might get a File, and then a FileReader, and then decorate it BufferedReader etc etc. In PHP I think it's much more straight forward. PHP itself is a very simple language, but it might take some time to make the change.

If the project *needs* to run on as many hosts as possible then PHP is a great choice. But some things you describe, like shared memory between requests, need special software anyway.

Quote:
But it sounds like you can use strings instead of integers to index arrays in PHP? How does that work? I know you could write a function to loop through the array until it finds a match, but is there a better method, out of the box?
In PHP arrays can be indexed by string or integer. And there is no difference between the two. Arrays are arrays, you can even mix integer keys with string keys. You can loop over arrays with a foreach construct.

Here's an example:

PHP Code:
$array = array(
    
'hello' => 'world',
    
=> 'zero',
    
'chroder' => 'member',
    
99 => 'ninety nine'
);

foreach (
$array as $key => $val) {
    echo 
"$key$val\n";
}

// hello:world
// 0: zero
// etc 
See Arrays in the PHP manual for more examples and explanations.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How do you cache lists?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19141 seconds with 12 queries