views:

113

answers:

4

Hey all,

I have a PHP class I want to convert to a PHP extension. I checked some tutorials and it's a bit complicated (see here, here and here).

It's just a hard work.

I found this – a simple example with few andn small files. So wanted to ask if it is possible to use this to make it grab a PHP class from a certain path (say /home/website1/public_html/api/class.php), execute it and return the class instance.

This way it will be usable in all others websites that are hosted on the same server – just call the function and you got your instance.

Is that possible ?

A: 

In one sentence: I don't believe so, I think its a lot more work than that.

Mark
+1  A: 

The question as I understand it now is, The user has a PHP class that they would like to share with multiple people, but does not want to share the source code.

There are many solutions to this, they generally invovle turning the PHP code into some kind of byte code, and using a PHP extension to run the byte code. I've never used any of these solutions, but I'm aware of the following:

I'm sure there are others. Just Google for PHP Compiler, or PHP Accelerator.

bramp
A: 

No, there is not tool that can do that.

Anyway, what you want call be easily accomplished with auto_prepend_file. Just make that ini directive point to a PHP file that has the class definition, and then it will be available to all the applications.

If you don't want the users to be able to use the source, you can use one the several zend extensions that allow you to pre-compile the file and use it in that form.

Artefacto
i did use auto_prepend_file but i had a problem with open_basedir restriction, is there anything i can do to bypass it ?
Wiika
@Wikka Yes, you can the path where the file is to open_basedir.
Artefacto
can u give more information about it please ?
Wiika
A: 

Hi Wiika,

You can extend underlying C library functions into PHP space by writing PHP extensions. However, i think in your case you don't need to write one.

Abhinav Singh