Page 1 of 1

Creating and using self made php libraries

Posted: Tue Apr 29, 2008 9:46 am
by konrados
Hi, I'm new here.

I used to use another forum, but it's down now, I hope you'll help a newbie with this.

I own a few domains. As a C++ programmer, I thought about creating a "common" library of functions, classes etc. Without copying it everywhere I need it, but rather referencing to it (including it).

And here is my concept: To put the library (php files) on one server (domain) and use them everywhere I want. Instead of giving them a .php extension (which won't work) I would use a "inc" or "include_me" or whatever extension. Then I'll use the include function on another domain/server to get it. I tried that and it works.

The question is - is there something I'm missing? Is there any danger ? Do you do that? I'm asking because I've read a biiiig and boring book about php and this "make my life easier" idea wasn't mentioned.

p.s. sorry for my English.

Re: Creating and using self made php libraries

Posted: Tue Apr 29, 2008 10:37 am
by John Cartwright
I think what your after is version control. Take a look at subVersion.

If your not familiar with the concept, it will basically allow you to update your code from a code repository instead of having to manually update code across multiple servers. You can also keep certain servers using different versions of the code incase there is some legacy.

Re: Creating and using self made php libraries

Posted: Tue Apr 29, 2008 11:26 am
by konrados
OK, thanks, but what about keeping the scripts on one server ? And updating them on this single server? Other servers would only include these files... isn't this a better idea?

Re: Creating and using self made php libraries

Posted: Tue Apr 29, 2008 12:20 pm
by konrados
No answer... so I'll try to clarify this. I have a few domains, and from time to time I need to use a function which looks like this:

Code: Select all

function SomeCommonFunction_CleanText($text) {
    $text = ereg_replace('&', '&', $text);
    $text = ereg_replace('<', '<', $text);
    $text = ereg_replace('>', '>', $text);
    return $text;
}
Let's call it "a very common function". Now - every time I need it on a new domain, I copy it to this new domain.

Now, just as a test, I put it on one domain, in file "super_cool_functions.inc" - and included it in another php file being on another server and it worked.

Is there something wrong with the idea of putting all the "common" functions and classes on one server with an .inc extension and then using them? (I'm a php novice).

Re: Creating and using self made php libraries

Posted: Tue Apr 29, 2008 1:31 pm
by konrados
OK, I know the answer now - including http files is simply much slower.

Re: Creating and using self made php libraries

Posted: Tue Apr 29, 2008 2:26 pm
by RobertGonzalez
Are the domains hosted on the same box?

Re: Creating and using self made php libraries

Posted: Tue Apr 29, 2008 3:06 pm
by konrados
Two of them yes, other two - no. The idea was to include via http:, but it seems I'll be copying the files from server to server as I used to be.

Re: Creating and using self made php libraries

Posted: Tue Apr 29, 2008 3:38 pm
by RobertGonzalez
The ones that are on the same box can just include along the file system. The others, not so sure.

Re: Creating and using self made php libraries

Posted: Tue Apr 29, 2008 5:08 pm
by Luke
I'm going to second the advice of using subversion. This keeps the code in one central location and allows you to keep local copies in sync very easily with the update command. Check it out.