Developing PHP extensions for Linux
Moderator: General Moderators
Developing PHP extensions for Linux
I am not sure if this is the right place to post this, but I am creating extensions for Linux.
It is tough because I come from a Windows background and it is difficult to compile programs in Linux. There are a lot of environmental complexities, especially to do with paths and libraries.
In the PHP source code download, there is an ext folder containing the source for the various extensions that ship with PHP. Alas, none of them are easy to understand. I am just looking for a trivial "Hello World" example of extension-building.
I do not have time to learn much about gcc or Linux generally, I just need an example that works out of the box. I will just change/add the C code.
Does anyone know where such an example can be found?
Thanks!
It is tough because I come from a Windows background and it is difficult to compile programs in Linux. There are a lot of environmental complexities, especially to do with paths and libraries.
In the PHP source code download, there is an ext folder containing the source for the various extensions that ship with PHP. Alas, none of them are easy to understand. I am just looking for a trivial "Hello World" example of extension-building.
I do not have time to learn much about gcc or Linux generally, I just need an example that works out of the box. I will just change/add the C code.
Does anyone know where such an example can be found?
Thanks!
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Probably not. I never seen a post about this before.I am not sure if this is the right place to post this, but I am creating extensions for Linux.
I'm guessing you've tried google.a trivial "Hello World" example of extension-building.
Well then you aren't going to get very far I imagine. I have looked into it a little and the only thing I can remember from doing so was that it requires a lot of patience and learning.I do not have time to learn much about gcc or Linux generally
What are you trying to achieve anyway?
What makes you so sure that writing your own extension will be necessary?
If performance is your concern there are plenty of ways of improving PHP performance.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Developing PHP extensions for Linux
IMO compiling code on Linux is easier than windows.... it's such common practise even for non-programmers since that's how we often install apps and the compilers are almost expected to just be there. GNU provides nice tools to make it easier to package your code up for others to compile too (automake, buildconf etc).anroy wrote:I am not sure if this is the right place to post this, but I am creating extensions for Linux.
It is tough because I come from a Windows background and it is difficult to compile programs in Linux. There are a lot of environmental complexities, especially to do with paths and libraries.
In the PHP source code download, there is an ext folder containing the source for the various extensions that ship with PHP. Alas, none of them are easy to understand. I am just looking for a trivial "Hello World" example of extension-building.
I do not have time to learn much about gcc or Linux generally, I just need an example that works out of the box. I will just change/add the C code.
Does anyone know where such an example can be found?
Thanks!
Writing PHP extensions... well, if you know C then it's actually pretty simple.
Here's your "Hello World!" example you were asking for
http://www.zend.com/php/internals/exten ... iting1.php (Most of that code is skeleton stuff)
`phpize' will make your extension work with your PHP installation for testing.
And take a look at http://pear.php.net/package/CodeGen_PECL
You bet!I'm guessing you've tried google.
That is what I am worried about. I personally have the patience, but my company doesn't.Well then you aren't going to get very far I imagine. I have looked into it a little and the only thing I can remember from doing so was that it requires a lot of patience and learning.
Yes, totally, performance is the issue. My program is a very mathematically intensive one, used on the back-end of a web service.What are you trying to achieve anyway?
What makes you so sure that writing your own extension will be necessary?
If performance is your concern there are plenty of ways of improving PHP performance.
Now the math is not all that advanced, just a bunch of multiplications and divisions. But there are millions and millions of them through a loop.
I wonder how much this can be optimized in PHP. Particularly since it is a web service the user is forced to wait for it. It will run much faster in C for sure.
Re: Developing PHP extensions for Linux
That is what many people say. But there is a learning curve. In Windows it is all nicely set up for you with Visual C++ whereas in Linux it is all command line. I think I will get used to it but unfortunately right now there are severe time pressures.IMO compiling code on Linux is easier than windows.... it's such common practise even for non-programmers since that's how we often install apps and the compilers are almost expected to just be there. GNU provides nice tools to make it easier to package your code up for others to compile too (automake, buildconf etc).
For me, the C part is very easy! It is the whole environment stuff that boggles the mind.Writing PHP extensions... well, if you know C then it's actually pretty simple.
Thank you for the link, it looks pretty friendly and written simply. Will definitely check this one out, it may just be the thing that saves me!Here's your "Hello World!" example you were asking for
http://www.zend.com/php/internals/exten ... iting1.php (Most of that code is skeleton stuff)
`phpize' will make your extension work with your PHP installation for testing.
I am actually not sure what PEAR is.volka wrote:And take a look at http://pear.php.net/package/CodeGen_PECL
I see the word a lot, in anything related to PHP. I would rather not have to worry about a new thing like that. But thanks for the link, will check it out if I have time!
anroy wrote:I am actually not sure what PEAR is.
http://pear.php.net/manual/en/introduction.php wrote:PEAR is short for "PHP Extension and Application Repository" and is pronounced just like the fruit.
The php source package contains the script ext/ext_skel that can be used to create an extension skeleton.
But afaik its not maintained any longer.
http://pear.php.net/package/CodeGen_PECL wrote:CodeGen_PECL (formerly known as PECL_Gen) is a pure PHP replacement
for the ext_skel shell script that comes with the PHP 4 source.
It reads in configuration options, function prototypes and code fragments
from an XML description file and generates a complete ready-to-compile
PECL extension.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
I appreciate the kind offer, thanks.ole wrote:dw about PEAR its the place where all the terrible PHP code is locked away.
Could you post your code please? I might be able to speed it up.
However it is confidential technology and my employers would kill me. Not that it is anything great, but they seem to think so. Tech companies all suffer from the same hubris.
Anyway, the logic just consists of a sequence of some arithemetic operations. Adds, subtracts, multiplications and divisions on 12-tuple arrays of floating points. This logic is applied on hundreds of thousands of DB records, each of which contains that 12-tuple of floats.
The MySQL DB access is not the cause of the slowness. I read in all the records first and set up the arrays. I have confirmed that this step is very quick. It is looping through all of them doing those arithmetic operations that takes time.
I know a few optimization tricks from my younger days as a C++ game programmer, such as multiplying by 0.5 rather than dividing by 2, and stuff like that.
Do you have such a bag of tricks you can share, or refer me to?
I am not sure if the common-sense rules in the C/C++ world also apply to PHP. I programmed in those languages for 15 years but have been doing PHP only a few months.
Sorry, that is confidential right now. I will give you guys the URL in a few months when this thing is complete... but if I cannot speed it up it will not go live.Weirdan wrote:Just curious, what is it for?Adds, subtracts, multiplications and divisions on 12-tuple arrays of floating points. This logic is applied on hundreds of thousands of DB records, each of which contains that 12-tuple of floats.
