Need serious help with PHP (constants and require_once)



  •  I have two webservers. One is apache, one is IIS. Configuration is the same, php is set up the same, source code is the same. Yet the Apache works, and the IIS does not. The apache one is my laptop, the development server, the IIS one is a crappy server that's the production server.

    The php web app is set up so every page has a require_once and it requires the config page. The config page defines all the constants for the web app, pretty much every page has to have it. And it works fine with apache. However, when this happens in IIS, it trys to include the file everytime throwing 30-40 notices that screws up the application and all kinds of other crap. However, if I check and see if the constants are defined already, and prevent them from being redefined, or turn off error reporting, I get nothing. As if the web app died. I'm stuck and I haven't the faintest clue what's going on. Does anyone else have an idea?



  • What do you mean by "it tries to include the file everytime"?  The file should be included on each page load, but it sounds like it is being loaded multiple times.  Do you have different require_once statements for it in the same page?  Presumably it should only need to be required on each page once, so this shouldn't be happening.  It sounds like you have different require_once statements with different paths for the same file (which will result in the same file being included multiple times).



  • Why would you not develop in an environment which even remotely approximates your production environment?



  •  Say I have this file called Page, and it needs the config file for the constants. It also needs files called Mysql, and Logger. Mysql and Logger also need the constants, so the also call the require_once for the constants. However, when they call it I get the warnings about them already being defined. However, if I remove their calls to that file the throw warnings about undefined constants assuming string literal.

     This is the exact same code that works perfectly on Apache.



  • @belgariontheking said:

    Why would you not develop in an environment which even remotely approximates your production environment?
     

    Because I don't have a choice.



  • @malfist said:

    Because I don't have a choice.
     

    You don't have a choice to run IIS on your development machine?



  •  I don't have a license for IIS, OEM XP, no CD to install IIS from. Please, can we stay on topic?



  • @malfist said:

     I don't have a license for IIS, OEM XP, no CD to install IIS from.
     

    So you are using XP Home for development then? Or you cannot borrow a CD to install IIS from? There is no additional license required for IIS.

    @malfist said:

    Please, can we stay on topic?

    As far as I can see this is on topic. BTK is right, you should be developing on something closely resembling your test environment.



  • XP Home doesn't include IIS, only PRO, as far as I know. On topic is dealing with the problems I need help with. I agree, testing/development on Apache and deployment on IIS is a bad idea, but that's not the focus of the issue here.



  • @malfist said:

    XP Home doesn't include IIS, only PRO, as far as I know.
     

    Yes, I am well aware. That is why I asked. If you are using Home edition for development (read: business) use, then you have another WTF!

    @malfist said:

    On topic is dealing with the problems I need help with.

    I don't think anyone here will be able to help you with the rat's nest of code you have there, but we could possibly help you learn some better development practices.

    @malfist said:

    but that's not the focus of the issue here.

    It is now.



  • @malfist said:

    Say I have this file called Page, and it needs the config file for the constants. It also needs files called Mysql, and Logger. Mysql and Logger also need the constants, so the also call the require_once for the constants.

    However the constants used by Mysql and Logger are both already included by Page so you do not have to include the file again.  It sounds like you are using a different path in different places with the require_once.  Perhaps you are using a relative path in some places and absolute in others?  Is the Apache box running on Linux?  If so, are you using the DIRECTORY_SEPARATOR constant in your includes or are you using a literal slash or backslash?  The latter may seem to work but it sounds like PHP thinks the file requested by require_once has not already been included.



  •  I'll change them all to absolute, see if that fixes anything. No, my apache isn't running linux :( My ubuntu box is at home.



  •  I appologize I am using substandard equipment that I have no control over. I'm glad to know that the fact that I cannot get XP Pro or IIS for development at my work place makes my code a rats nest. Sorry to offend your delicate sensibilities. Now, if you're just going to troll and not help, please go away.



  • @malfist said:

     I appologize I am using substandard equipment that I have no control over
     

    Using the wrong version of an OS and webserver is akin to a carpenter using a screwdriver to drive a nail instead of a hammer. You don't need to apologize to anyone, but making excuses is silly.

    Stop what you are doing, and get the proper setup before proceeding.

    @malfist said:

    I'm glad to know that the fact that I cannot get XP Pro or IIS for development at my work place makes my code a rats nest.

    I have a feeling that your rat's nest is a whole different, larger issue that needs to be addressed. For now, you should start with the easy and obvious stuff like using the right tool for the job.

    @malfist said:

    Now, if you're just going to troll and not help

    No one here is trolling. Everyone here so far has been trying to help you.



  •  Really now? Because I work for a messed up buisness called a univeristy and I have to deal with Windows servers running IIS and an outdated version of PHP and MySQL (3.23 anyone?) instead of stable linux servers running apache with fully updated software, it's my fault. As a student worker, I don't have the privilage to ask for the 'right tools'. If I started doing that, I'd be looking for a new job. Not everybody works for google you know.



  • @malfist said:

    instead of stable linux servers running apache with fully updated software
     

    Where did anyone even advise this?

    @malfist said:

    Not everybody works for google you know.

    And now I know why you never will.

    Google has a minimum requirement: "Applicant should be able to read."



  •  It's good to know that I can't read, I thought that was an integral part of writing.



  • Just ignore the trolls. It won't make them go away but it prevents you from wasting time.

    Internet Argument



  • @brazzy said:

    Just ignore the trolls. It won't make them go away but it prevents you from wasting time.
     

    Once again, there is no one trolling here. 

    However posting LOLcat style pictures in a serious thread where someone is asking for help could definitely be considered trolling.



  • @MasterPlanSoftware said:

    @malfist said:

     I appologize I am using substandard equipment that I have no control over
     

    Using the wrong version of an OS and webserver is akin to a carpenter using a screwdriver to drive a nail instead of a hammer. You don't need to apologize to anyone, but making excuses is silly.

    Stop what you are doing, and get the proper setup before proceeding.

    One friend of mine was forced to develop and deploy an application on their "server", with no development box available. The "server" was a Windows 2000 Professional box. She would've preferred a win2000 server, or a linux box; but management didn't want to. Oh, and the DBMS was Access, because she couldn't get them to install a real DBMS either. I think by now you're getting what big of a WTF management was at her job. You might even be thinking if this is a cheap-ass Mom & Pop business (like the "Hot Water Costs Money!" story).

    It isn't. The place she was working at is GM.

    WTF indeed.



  • @danixdefcon5 said:

    You might even be thinking if this is a cheap-ass Mom & Pop business (like the "Hot Water Costs Money!" story).

    It isn't. The place she was working at is GM.

    WTF indeed.

    Yeah, but GM has been hemorrhaging money and market share for decades.  I think it's kind of evident at this point that the company has shitty, shitty management. 


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.