Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8024301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:49:45+00:00 2026-06-04T22:49:45+00:00

I am trying to implement a hashmap (associative array in PHP) in PHP which

  • 0

I am trying to implement a hashmap (associative array in PHP) in PHP which is available application wide i.e store it in application context, it should not be lost when the program ends. How I can I achieve this in PHP?

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:49:47+00:00Added an answer on June 4, 2026 at 10:49 pm

    If you are using Zend’s version of php, it’s easy.
    You do not need to serialize your data.
    Only contents can be cached. Resources such as filehandles can not.
    To store true/false, use 1,0 so you can differentiate a cache failure from a result with ===.

    Store:

    zend_shm_cache_store('cache_namespace::this_cache_name',$any_variable,$expire_in_seconds);
    

    Retrieve:

    $any_variable = zend_shm_cache_fetch('cache_namespace::this_cache_name');
    
    if ( $any_variable === false ) {
        # cache was expired or did not exist.
    }
    

    For long lived data you can use:

    zend_disk_cache_store();zend_disk_cache_fetch();
    

    For those without zend, the corresponding APC versions of the above:

    Store:

    apc_store('cache_name',$any_variable,$expire_in_seconds);
    

    Retrieve:

    $any_variable = apc_fetch('cache_name');
    
    if ( $any_variable === false ) {
        # cache was expired or did not exist.
    }
    

    Never used any of the other methods mentioned.
    If you don’t have shared memory available to you, you could serialize/unserialize the data to disk. Of course shared memory is much faster and the nice thing about zend is it handles concurrency issues for you and allows namespaces:

    Store:

    file_put_contents('/tmp/some_filename',serialize($any_variable));
    

    Retrieve:

    $any_variable = unserialize(file_get_contents('/tmp/some_filename') );
    

    Edit: To handle concurrency issues yourself, I think the easiest way would be to use locking. I can still see the possiblity of a race condition in this psuedo code between lock exists and get lock, but you get the point.

    Psuedo code:

    while ( lock exists ) {
        microsleep;
    }
    get lock.
    check we got lock.
    write value.
    release lock.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a HashMap-based tree that'd support O(1) subtree lookup for a
PS: the reference link www.­androidpeople.­com/­android-­custom-­listview-­tutorial-­part-­1 is not available. Dears, I am trying to create
I am trying to implement a custom view, for which I want to be
I have a service running in my Android application which contains a HashMap that
In Java, I'm trying to retrieve a HashMap<String, Object> that has the Object which
I'm trying to implement a simple Facebook chat application on Android. It lets the
I'm trying implement a custom login page to use in my JSF 2.0 application.
Trying to implement the following behavior on an iPad. I have a map-centric application
I am trying to implement a RESTful service endpoint which produces XML responses. The
I'm trying implement a way to recursively template using jsRender. The issue is, my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.