Can we build PHP 5 Class?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
olog-hai
Forum Commoner
Posts: 34
Joined: Thu May 31, 2007 8:47 am
Location: Québec city, QC, Canada

Can we build PHP 5 Class?

Post by olog-hai »

Hi,

I just want to know if it's doable to build or compile php5 class ? Apache 2 can support this ?

Thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Do you want to write an php extension module (not in php itself but maybe C/C++) that exports a php class?
User avatar
olog-hai
Forum Commoner
Posts: 34
Joined: Thu May 31, 2007 8:47 am
Location: Québec city, QC, Canada

Post by olog-hai »

Is it the way to work with php 5 compiled class ?

I've a web site that use PHP 5 class, I want to know if I can compile this class and use them ? it's only for a performance purpose

in other word: Like microsoft .NET, all class is compiled and ISS load these compiled class in memory and work with them.
with PHP5 and Apache 2, can we have this kind of behavior ?

compiled class is really faster than interpreted php file right ?

thanks.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

In a word: No.
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Post by DaveTheAve »

I believe I understand where your coming from, you want to know if you can compile your script into machine-code and be interpreted ONCE, instead of wasting precious time interpreting it EVERY run just to get the same effect with more time wasted.

The Answer is:
Yes and No, unlike what you have read above, not saying they're wrong (once they see what I'm talking about they'll agree or research it), but they are forgetting an important extension for PHP. I'm not sure how fimilar you are with Caches (now you ppl know where I'm going?), but there is a little program called APC (http://us.php.net/apc) that, once a script is first compiled, will save the machine-coded version in a cache for a preset time. Please note however, that doing this has it's "ups and downs", while increasing speed and productivity, it will not work for most dynamic corners of web applications. I suggest you do more research into this program and test it out before going public.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I'll reiterate what Jenk said: No.

PHP is interpreted, .NET is compiled. Big difference, but a difference that has it's goods and bads.

What is your desired for a compiled language framework?
User avatar
olog-hai
Forum Commoner
Posts: 34
Joined: Thu May 31, 2007 8:47 am
Location: Québec city, QC, Canada

Post by olog-hai »

I wanted to know if PHP get a compile mode.

Is PHP is on the way to get a framework in the futur version ? .PHP 6 Framework :)

thanks.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Search for PHP Framework, either here or on your favorite search engine.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I think as long as PHP is interpreted then no, it won't have a framework like the .NET framework, if that is what you are asking. But can I ask again, what is your desired for a compiled language framework?
User avatar
olog-hai
Forum Commoner
Posts: 34
Joined: Thu May 31, 2007 8:47 am
Location: Québec city, QC, Canada

Post by olog-hai »

I have no desire for compiled language framework, but I've desire for my wife :).

My first goal is to get my web site faster, and I always heard that compiled language is faster than interpreted. So it was my question.

and you, do you have preference and why ?

thanks.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

There are ways of compiling PHP into a byte-code so it executes at speeds equivelant to ASP.NET however neither will come close to a well tuned nativley compiled C application.

Writing CGI using plain vanilla C is a *lot* of work thats why most just stick to Perl or PHP. Unless the speed increase is really needed the etrax effort isn't worth it.

There is however a PHP compiler, which does something similar to a native C compiler.

Google for Roadsend you'll find there. :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

If your web site is slow then the overhead of compiling the PHP code is not going to make any noticable difference. We're talking about milliseconds here. Sounds like you need to optimize your PHP code before doing anything else ;)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Seriously, PHP interprests very quickly. In many cases, .NET apps run at the same speed as PHP apps run when the servers (web, file, database, etc) are all configured properly AND the code used in the app is optimized correctly. Overall speed differences are negligible when it comes to performance. In my opinion.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

olog-hai wrote:My first goal is to get my web site faster
Is your website actually slow?

If it is, have you tried the 1000s of things you could do to speed it up?
olog-hai wrote:I always heard that compiled language is faster than interpreted. So it was my question.
You always heard wrong.
(#10850)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

You need to profile your application and start wood-shedding the parts that are slow.

But to answer your question, you can cache PHP's "opcodes" using APC.
Post Reply