Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2006
    Location
    Oslo, Norway
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Where to place objects/functions

    I have some core functions, say object.php and functions.php which are useful for a lot small php programs I've made.

    Should I place that code in for instance a directory called "core" and let all the other programs use it like this:
    /core
    /program1 (calling core functions)
    /program2 (calling core functions)
    ... and so on

    Or should I copy the core functions into each and every other program directory, like this:
    /program1/core
    /program2/core
    ... and so on

    Main question: If many useres try to access a php-file at the same time, is that a problem, or is the prosess forked (or something like that)?

    Regards and thanks for some opinions!
    DrÝmmejenta: Kristen jente som progger Python!

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    keeping them in one place is preferable, so that if you discover, for example, that your generic file-opening script has a security-flaw in it, you only need to worry about a single fix- likewise if you decide there's a way to optimise a function.
    The downside, though, is that if you find you need to make a change to one of these functions, to make it more generic and suitable for a new task for example, you'll have to either ensure the interface remains constant (so that things that are calling the 'old' version still work) or make changes to existing code.
    Also, if you do need to make changes, you better be certain that they're not going to break anything if you've got multiple things depending on them.
    One option would be to use source-control, subversion for example, and have a single copy of the code that changes get made to, and then the versions inside the applications are checkouts of the repository.
    This would mean that you can make the changes in a single place and test by checking out to one of your applications. If you see there are problems, you can revert back to the 'good' copy straight away, otherwise carry on the roll-out to everything else.

    Multiple reads on a single file won't cause you problems until you get very high load.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •