Creating and using self made php libraries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
konrados
Forum Newbie
Posts: 17
Joined: Tue Apr 29, 2008 9:32 am

Creating and using self made php libraries

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Creating and using self made php libraries

Post 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.
konrados
Forum Newbie
Posts: 17
Joined: Tue Apr 29, 2008 9:32 am

Re: Creating and using self made php libraries

Post 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?
konrados
Forum Newbie
Posts: 17
Joined: Tue Apr 29, 2008 9:32 am

Re: Creating and using self made php libraries

Post 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).
konrados
Forum Newbie
Posts: 17
Joined: Tue Apr 29, 2008 9:32 am

Re: Creating and using self made php libraries

Post by konrados »

OK, I know the answer now - including http files is simply much slower.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Creating and using self made php libraries

Post by RobertGonzalez »

Are the domains hosted on the same box?
konrados
Forum Newbie
Posts: 17
Joined: Tue Apr 29, 2008 9:32 am

Re: Creating and using self made php libraries

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Creating and using self made php libraries

Post by RobertGonzalez »

The ones that are on the same box can just include along the file system. The others, not so sure.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Creating and using self made php libraries

Post 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.
Post Reply