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 8225813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:32:33+00:00 2026-06-07T15:32:33+00:00

I have a PHP script that will throw exceptions (e.g. cannot connect to server).

  • 0

I have a PHP script that will throw exceptions (e.g. cannot connect to server). In the development arena I would like as much information to be on the screen, but in production I do not want to give the game away. But I would like some code that works in both environments and also enables me to further develop the code.

Is there a prescribed technique to achieve this?

EDIT

Yes using apache with PHP

But how to distinguish between the production environment and the development environment without having to change the code base.

  • 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-07T15:32:34+00:00Added an answer on June 7, 2026 at 3:32 pm

    You usually deal with this with environment variables. It can be a configuration file .php (or .ini, .yml, .xml, whatever you use for config files) that you load on startup, and has environment-specific values. For example, in your production server, your environment config file might look like this:

    $config['environment'] = 'production';
    

    Another option is to use environment variables provided by your web server. Both approaches are fine, though I prefer the former.

    Then you catch ALL uncaught exceptions (and also turn errors into exceptions. Having errors disabled can be annoying during development, and having errors enabled and not catching them can be a huge security hole in production) with an ‘universal error catcher’ (I haven’t tried this one, but looks good. In the past I used one I wrote myself, but it was very tricky, I don’t recommend writing your own catcher, other than for learning purposes). Then just do something like this:

    if($config['environment'] == 'production') {
        echo 'Oops, something went wrong';
    } else {
        // print full backtrace and stuff
    }
    

    As a sidenote, this is the kind of problem a ‘framework’ is supposed to solve for you. If you use Silex or Symfony 2, this functionality is available by default.

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

Sidebar

Related Questions

I have a PHP script that very much like a commenting system, but requires
I have a simple PHP script that will either serve up a streaming ASF
I have a PHP script running on XAMPP in Windows XP that will open
I have a PHP script that will generate a report using PHPExcel from data
I have a php script that will an catch email passed to it and
I have a PHP script that will generate <input> s dynamically, so I was
I have a PHP script involving exec() that will run fine from the command
I have a PHP script that will run for a long time. I have
I have a PHP script that needs to execute programmes that will work on
I have an jquery ajax request that calls a PHP script that will send

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.