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

  • Home
  • SEARCH
  • 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 397683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:40:28+00:00 2026-05-12T16:40:28+00:00

I am just now switching back to PHP after enterprise open-source Java development for

  • 0

I am just now switching back to PHP after enterprise open-source Java development for three years. Now I am tasked with updating our platform for better logging.

I now understand better how the PHP object lifecycle regarding when objects are garbage collected and have trapped my problem. I am trying to invoke the logger after its already been destructed, when a fatal error occurs. My question is, how do I fix this? How can I stop an object from being destroyed until the end of the request?

Ideally I would like to keep this logger around in memory like I would in Java but is that even possible with PHP? Is there anything shared between two different threads or requests?

  • 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-05-12T16:40:28+00:00Added an answer on May 12, 2026 at 4:40 pm

    With PHP, each request is processed by a different process — which means you quite cannot keep some object arround between requests (you could serialize it and store it in a file or something like that, and un-serialize it when another requests comes ; but that’s not really the way things are generally done)

    This means each time your PHP script receives a request, you have to re-instanciate your logger.

    Now, if you want to use your logger from several different classes/methods/functions in the same script, you have to know that variables are not global “by default” in PHP : a variable declared outside of a function is not accessible from inside a function, unless you said so using the global keyword.

    In this kind of situation, when you want one and only one instance of a specific class (your logger) available from anywhere in your application, people often use the Singleton Design Pattern.

    It’ll allow to use something like this :

    My_Logger_Class::log('blah');
    

    From any portion of your code, and the log method will deal with :

    • instanciating the class if there was not already one existing instance
    • the actual logging

    And, yes, the first time this method is called for one HTTP request, it’ll have to re-open the log file (if logging to a file).

    As a sidenote : there are already some existing great logging components, like PEAR::Log or Zend_Log.

    Maybe using one of those might help you spend less time re-inventing some wheel ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 215k
  • Answers 215k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Havent tried it yet but there is a class called… May 12, 2026 at 10:58 pm
  • Editorial Team
    Editorial Team added an answer Not much in the way of well-supported libraries for ADSI-java… May 12, 2026 at 10:58 pm
  • Editorial Team
    Editorial Team added an answer GCC implementation of reserve() will allocate exact number of elements,… May 12, 2026 at 10:58 pm

Related Questions

I am trying to understand if I really have any case for using git/mercurial.
I've work in embedded systems and systems programming for hardware interfaces to date. For
I've previously documented my opinions on Clearcase as a source control system, but unfortunately
My situation is that I screwed up essentially. I inherited my code base about

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.