dynamically loadable php files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kishore.sainath@gmail.com

    dynamically loadable php files

    I have created a set of classes in PHP for internal use in the company.

    Hence I don't explicitly want to "require" or "require_on ce" them
    whenever required.

    I want to make the library loadable on demand just like mysql or other
    libraries in php. I want people to use the classes in my library
    without "requiring" anything.

    In a nutshell, I want to make my PHP library a .so file in Linux and a
    ..dll file in Windows.

    How do I achieve this?

    I currently need a solution for the following combination
    Linux, Apache and PHP 5.0.4.

    I also welcome a solution on Windows.

    Thanks in advance
    - Kishore

  • Wolfgang Forstmeier

    #2
    Re: dynamically loadable php files

    Hi,

    have a look @ the PHP - Manual of new Object model in PHP 5.x
    here you could fine the method __autoload() this is exactly what u want :)

    Have Fun ..

    Wolfgang ..

    kishore.sainath @gmail.com wrote:[color=blue]
    > I have created a set of classes in PHP for internal use in the company.
    >
    > Hence I don't explicitly want to "require" or "require_on ce" them
    > whenever required.
    >
    > I want to make the library loadable on demand just like mysql or other
    > libraries in php. I want people to use the classes in my library
    > without "requiring" anything.
    >
    > In a nutshell, I want to make my PHP library a .so file in Linux and a
    > .dll file in Windows.
    >
    > How do I achieve this?
    >
    > I currently need a solution for the following combination
    > Linux, Apache and PHP 5.0.4.
    >
    > I also welcome a solution on Windows.
    >
    > Thanks in advance
    > - Kishore
    >[/color]

    Comment

    • kishore.sainath@gmail.com

      #3
      Re: dynamically loadable php files

      I see that __autoload in a global function.

      My problem is where do it define the function.

      I don't want to do it in the file where use a class.

      - Kishore

      Comment

      • ZeldorBlat

        #4
        Re: dynamically loadable php files

        Define it at the very top of your page. Once it's been defined, you
        don't need to define it again. If you're lucky, you have some header
        or something that already get's included at the top of every page, so
        you could just add it there.

        Comment

        • kishore.sainath@gmail.com

          #5
          Re: dynamically loadable php files

          To avoid all this hassle, is there a way to create a .dll or a .so
          file.

          A file that I could put in the directory where the mysql and other
          libraries reside.
          So that I can call them just like any other pre-defined function or
          class.

          Comment

          • Wolfgang Forstmeier

            #6
            Re: dynamically loadable php files

            Sure you can.
            You have just to write an PHP - Extension ..
            Then you could it use as an PHP Function.


            kishore.sainath @gmail.com wrote:[color=blue]
            > To avoid all this hassle, is there a way to create a .dll or a .so
            > file.
            >
            > A file that I could put in the directory where the mysql and other
            > libraries reside.
            > So that I can call them just like any other pre-defined function or
            > class.
            >[/color]

            Comment

            • NC

              #7
              Re: dynamically loadable php files

              kishore.sainath @gmail.com wrote:[color=blue]
              >
              > I have created a set of classes in PHP for internal use in the company.
              >
              > Hence I don't explicitly want to "require" or "require_on ce" them
              > whenever required.
              >
              > I want to make the library loadable on demand just like mysql or other
              > libraries in php.[/color]

              MySQL library usually is NOT loadable "on demand". It is loaded
              at the server startup.
              [color=blue]
              > I want people to use the classes in my library without "requiring"
              > anything.[/color]

              Then use the auto_prepend_fi le directive in php.ini. This way,
              PHP will parse your file(s) every time it parses anything, and
              your classes will be available to any PHP script on your server
              without explicitly incluing/requiring them.
              [color=blue]
              > In a nutshell, I want to make my PHP library a .so file in Linux
              > and a .dll file in Windows.
              >
              > How do I achieve this?[/color]

              You can't. If you want to use the extension mechanism, you have to
              write your extension in C.

              Cheers,
              NC

              Comment

              Working...