Page 1 of 2

What is PHP core?

Posted: Tue Sep 21, 2010 1:24 am
by abalfazl
1-What is PHP core?
2-How does it work?
3-What is Zend engine?
4-Which language is used to build PHP core(For PHP 5) and zend engine?
5-What is relationship between C and PHP 5?

Re: What is PHP core?

Posted: Tue Sep 21, 2010 7:56 am
by Ragnis
5. PHP is written in C

Re: What is PHP core?

Posted: Tue Sep 21, 2010 7:56 am
by josh

Re: What is PHP core?

Posted: Tue Sep 21, 2010 8:23 am
by Eran
As far as I can tell, it's written in C.

Re: What is PHP core?

Posted: Tue Sep 21, 2010 8:29 am
by abalfazl
Again: What is PHP core and how does it work?

Re: What is PHP core?

Posted: Tue Sep 21, 2010 10:48 am
by alex.barylski
A quick checkout from SVN of 5.2:

Code: Select all

469317  ext             ansic=450035,sh=8399,php=7377,yacc=1483,tcl=1128, awk=860,pascal=35
63119   Zend            ansic=58435,lex=2296,php=1441,yacc=947
19304   main            ansic=19304
17619   sapi            ansic=16818,cpp=682,php=119
11522   top_dir         sh=8417,php=3105
3550    regex           ansic=3489,sh=61
3243    win32           ansic=2917,php=326
2677    TSRM            ansic=2652,sh=25
1681    build           sh=1534,awk=147
931     scripts         php=506,sh=387,awk=38
744     tests           php=671,perl=71,pascal=2
75      netware         ansic=75
64      pear            php=64


Totals grouped by language (dominant language first):
ansic:       553725 (93.24%)
sh:           18823 (3.17%)
php:          13609 (2.29%)
yacc:          2430 (0.41%)
lex:           2296 (0.39%)
tcl:           1128 (0.19%)
awk:           1045 (0.18%)
cpp:            682 (0.11%)
perl:            71 (0.01%)
pascal:          37 (0.01%)
PHP is indeed (excluding externals) 93.4% written in ANSI C. :)

Cheers,
Alex

Re: What is PHP core?

Posted: Tue Sep 21, 2010 10:50 am
by alex.barylski
Again: What is PHP core and how does it work?
Your asking the wrong crowd, most of us are primarily interested in using PHP not building it. The architecture is complex and highly optimized. You could probably learn a great deal by sifting through the code, implementing some basic extensions, etc. I have Googled many times in the past and found very little on the subject so I suspect your in for the same ride.

So again, start Googling. ;)

Cheers,
Alex

Re: What is PHP core?

Posted: Tue Sep 21, 2010 12:41 pm
by ell0bo
The core of the code in written in C, however extensions and the like can be written in C++. The difference between to two, as far as this forum goes, is negligible.

Re: What is PHP core?

Posted: Tue Sep 21, 2010 12:46 pm
by alex.barylski
The core of the code in written in C, however extensions and the like can be written in C++.
You might be bale to, but would it make sense to use C++? I recall the extension API having to confirm to a specific calling convention (which C++ could do) but then there is the issue of resolving the *this* pointer.

So the API would almost certaily have to be built as a C library and the implementation of each function could use objects internally, but at that point, I would just stick with C.

Cheers,
Alex

Re: What is PHP core?

Posted: Tue Sep 21, 2010 1:15 pm
by abalfazl
Your asking the wrong crowd, most of us are primarily interested in using PHP not building it. The architecture is complex and highly optimized. You could probably learn a great deal by sifting through the code, implementing some basic extensions, etc. I have Googled many times in the past and found very little on the subject so I suspect your in for the same ride.

Thanks for answer, But of course someone here work with PHP core and help me

Re: What is PHP core?

Posted: Tue Sep 21, 2010 1:28 pm
by ell0bo
PCSpectra wrote:
The core of the code in written in C, however extensions and the like can be written in C++.
You might be bale to, but would it make sense to use C++? I recall the extension API having to confirm to a specific calling convention (which C++ could do) but then there is the issue of resolving the *this* pointer.

So the API would almost certaily have to be built as a C library and the implementation of each function could use objects internally, but at that point, I would just stick with C.

Cheers,
Alex
I don't remember entirely how it works, it's been about two years since I looked into writing my own extension, but I know it involved C++, because at this point thinking in C terms (aka procedurally) instead of c++ (OO) makes my head hurt.

Re: What is PHP core?

Posted: Tue Sep 21, 2010 8:21 pm
by josh
I have a book called "Extending & Embedding PHP". I didn't read it yet but the index implies the 'core' is related to the following topics: core globals, core php functions (error reporting, misc, open basedir, output, reentrancy safety, safe mode, startup/shutdown,string formatting).

Re: What is PHP core?

Posted: Thu Sep 23, 2010 12:45 pm
by abalfazl
How does PHP core work?

I want to know what happened behind. Please show me by a simple PHP code, What happened in PHP core when that code runs.

Re: What is PHP core?

Posted: Thu Sep 23, 2010 5:33 pm
by Jonah Bron
abalfazl wrote:How does PHP core work?
Did you read the posts by everyone?
abalfazl wrote:... Please show me by a simple PHP code ...
It's not written in PHP, it's written in C.

Re: What is PHP core?

Posted: Thu Sep 23, 2010 8:53 pm
by josh
I think he wants help visualizing the parse tree that the php core seems like it would have to build.