[PHP-DEV] questions about php structures

2012-11-17 Thread Adi Mutu
Hello,

Got a few questions  if anybody can help me out:

1) what's the difference between zend_object and zend_object_value? what is 
each for? Because i'm confused..
2) What are zend_object_store_bucket; and zend_object_store used for?

Thanks,
A.

[PHP-DEV] error handler

2012-10-19 Thread Adi Mutu


Hello,

Can anybody show me, where in the core the user error handler is called? The 
mechanism of how it's called...

Thanks,
A.

[PHP-DEV] compile php as fpm

2012-08-20 Thread Adi Mutu
Hello,

I'm trying to compile php 5.3 as php-fpm using the following configure command


./configure --enable-debug --enable-maintainer-zts --enable-fpm --enable-fastcgi



and i get this 


Thank you for using PHP.

Notice: Following unknown configure options were used:

--enable-fastcgi



The command is from a tutorial on web. 
Thanks.


Re: [PHP-DEV] concatenation operator

2012-06-30 Thread Adi Mutu


By initialization i mean the latest point possible where I can set a 
breakpoint, but right before my scripts starts executing it's emalloc's or 
efree's.

 but even then you will see many things you're probably not interested in

such as?..

 Only thing that helps is learning the code structure and digging through it.

Any hint/documentation to learn that?

Thanks.




 From: Johannes Schlüter johan...@schlueters.de
To: Adi Mutu adi_mut...@yahoo.com 
Cc: Felipe Pena felipe...@gmail.com; PHP Developers Mailing List 
internals@lists.php.net 
Sent: Saturday, June 30, 2012 12:36 AM
Subject: Re: [PHP-DEV] concatenation operator
 
On Fri, 2012-06-29 at 11:47 -0700, Adi Mutu wrote:
 Sorry for the late reply, I was away for a while..
 I don't think I have dtrace because I'm on fedora.but i'll
 research.

As said: Currently only on Solaris, MacOS and BSD. Oracle is porting
DTrace to Oracle Linux. RedHat created SystemTap which is similar, ut I
have never used it.

 If i would want to set a breakpoint after php's initialization
 process, but right before the scripts execution, so that after that I
 can set breakpoints to emalloc and efree which are executed only
 during my scripts execution where should i set it? Hope the question
 was clear enough.

Depends on your view what initialization is. But execute() might be a
place which helps ... but even then you will see many things you're
probably not interested in. Only thing that helps is learning the code
structure and digging through it.

 dtrace related:
 Why have you used 'execute:return' and not concat_function:return?
 What's with the execute function?

That was a bug since I quickly edited an older script. In this case it
doesn't change the result.

johannes

Re: [PHP-DEV] concatenation operator

2012-06-29 Thread Adi Mutu
Hello,

Sorry for the late reply, I was away for a while..
I don't think I have dtrace because I'm on fedora.but i'll research.

If i would want to set a breakpoint after php's initialization process, but 
right before the scripts execution, so that after that I can set breakpoints to 
emalloc and efree which are executed only during my scripts execution where 
should i set it? Hope the question was clear enough.

dtrace related:
Why have you used 'execute:return' and not concat_function:return? What's with 
the execute function?


Thanks,
A.



 From: Johannes Schlüter johan...@schlueters.de
To: Adi Mutu adi_mut...@yahoo.com 
Cc: Felipe Pena felipe...@gmail.com; PHP Developers Mailing List 
internals@lists.php.net 
Sent: Thursday, June 7, 2012 11:18 PM
Subject: Re: [PHP-DEV] concatenation operator
 
On Thu, 2012-06-07 at 12:53 -0700, Adi Mutu wrote:
 Ok Johannes, thanks for the answer. I'll try to look deeper. 
 I basically just wanted to know what happens when you concatenate two
 strings? what emalloc/efree happens.

This depends. As always. As said what has to be done is one allocation
for the result value ... and then the zval magic, which depends on
refcount, references, ...

 Also can you tell me if possible how to put a breakpoint to
 emalloc/efree which are executed only after all core functions are
 registered? because it takes like a million years like this and a
 million F8 presses...

Depends on your debugger. Most allow conditional breakpoints or have a
breakpoint and while holding at some place add a few more ...

For such a question my preference is using DTrace (on Solaris, Mac or
BSD), something like this session:

        $ cat test.d
        #!/sbin/dtrace
        
        pid$target::concat_function:entry {
            self-in_concat = 1;
        }
        
        pid$target::execute:return {
            self-in_concat = 0;
        }
        
        pid$target::_emalloc:entry
        / self-in_concat /
        {
            trace(arg0);
            ustack();
        }
        
        pid$target::_erealloc:entry
        / self-in_concat /
        {
            trace(arg0);
            trace(arg1);
            ustack();
        }
        
        $ cat test1.php
        ?php
        $a = foo; $b = bar; $a.$b;
        
        $ dtrace -s test.d -c 'php test1.php'
        dtrace: script 'test.d' matched 4 probes
        dtrace: pid 16406 has exited
        CPU     ID                    FUNCTION:NAME
          3 100372                   _emalloc:entry                 7
                      php`_emalloc
                      php`concat_function+0x270
                      php`ZEND_CONCAT_SPEC_CV_CV_HANDLER+0xcd
                      php`execute+0x3d9
                      php`dtrace_execute+0xe7
                      php`zend_execute_scripts+0xf5
                      php`php_execute_script+0x2e8
                      php`do_cli+0x864
                      php`main+0x6e2
                      php`_start+0x83
        
        $ cat test2.php
        ?php
        $a = 23; $b = bar; $a.$b;
        
        $ dtrace -s test.d -c 'php test2.php'
        dtrace: script 'test.d' matched 4 probes
        dtrace: pid 16425 has exited
        CPU     ID                    FUNCTION:NAME
          1 100373                  _erealloc:entry                 0           
    79
                      php`_erealloc
                      php`xbuf_format_converter+0x11ee
                      php`vspprintf+0x34
                      php`zend_spprintf+0x2f
                      php`_convert_to_string+0x174
                      php`zend_make_printable_zval+0x5ec
                      php`concat_function+0x3c
                      php`ZEND_CONCAT_SPEC_CV_CV_HANDLER+0xcd
                      php`execute+0x3d9
                      php`dtrace_execute+0xe7
                      php`zend_execute_scripts+0xf5
                      php`php_execute_script+0x2e8
                      php`do_cli+0x864
                      php`main+0x6e2
                      php`_start+0x83
        
          1 100372                   _emalloc:entry                 6
                      php`_emalloc
                      php`concat_function+0x270
                      php`ZEND_CONCAT_SPEC_CV_CV_HANDLER+0xcd
                      php`execute+0x3d9
                      php`dtrace_execute+0xe7
                      php`zend_execute_scripts+0xf5
                      php`php_execute_script+0x2e8
                      php`do_cli+0x864
                      php`main+0x6e2
                      php`_start+0x83
        
So, when having two constant strings there's a single malloc, in this
case allocating 7 bytes (strlen(foo)+strlen(bar)+1), if you have a
different type it has to be converted first ...


johannes

Re: [PHP-DEV] Internals books (c) 2007+ ?

2012-06-10 Thread Adi Mutu
:)
That's too badI've read Sara's book, but i'd also buy a new book on this 
topic.



 From: Lars Strojny l...@strojny.net
To: Sanford Whiteman swhitemanlistens-softw...@cypressintegrated.com 
Cc: internals@lists.php.net 
Sent: Thursday, May 17, 2012 5:14 PM
Subject: Re: [PHP-DEV] Internals books (c) 2007+ ?
 
Yep, that might be exactly the problem. The audience for such a book might be 
less than 100.

Am 17.05.2012 um 06:24 schrieb Sanford Whiteman:

 Sara’s book is still the best we have, nevertheless it shows its
 age. In Theo Schlossnagles Scalable Internet Architectures also
 has a chapter on PHP internals. The rest is more or less reading
 existing code and playing around. Looks like somebody on Internals should 
 land a book deal :)
 
 Thanks, Lars. I first learned about zvals from a chapter in George
 Schlossnagle's Advanced PHP Programming, so it seems like there are
 deeper dives here and there. I don't know about the book deal if I'm
 the only to ask about it in so long, though. :)
 
 -- S.
 
 
 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php
 


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] concatenation operator

2012-06-07 Thread Adi Mutu


that's nice, but i haven't understood a thing...i know something about php core 
and php extensions, but nothing about the Zend engine specific. 
Can you point me to some resources on this topic?

Thanks,



 From: Felipe Pena felipe...@gmail.com
To: Adi Mutu adi_mut...@yahoo.com 
Cc: PHP Developers Mailing List internals@lists.php.net 
Sent: Tuesday, June 5, 2012 11:17 PM
Subject: Re: [PHP-DEV] concatenation operator
 
Hi,

2012/6/5 Adi Mutu adi_mut...@yahoo.com:


 Hello,

 Can somebody point me to where the concatenation operator is implemented ?  
 . operator.

 Thanks,

See http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_vm_def.h#133

-- 
Regards,
Felipe Pena

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] concatenation operator

2012-06-07 Thread Adi Mutu
Ok Johannes, thanks for the answer. I'll try to look deeper. 
I basically just wanted to know what happens when you concatenate two strings? 
what emalloc/efree happens.

Also can you tell me if possible how to put a breakpoint to emalloc/efree which 
are executed only after all core functions are registered? because it takes 
like a million years like this and a million F8 presses...

Thanks.



 From: Johannes Schlüter johan...@schlueters.de
To: Adi Mutu adi_mut...@yahoo.com 
Cc: Felipe Pena felipe...@gmail.com; PHP Developers Mailing List 
internals@lists.php.net 
Sent: Thursday, June 7, 2012 10:44 PM
Subject: Re: [PHP-DEV] concatenation operator
 
On Thu, 2012-06-07 at 11:50 -0700, Adi Mutu wrote:
 
 that's nice, but i haven't understood a thing...i know something about
 php core and php extensions, but nothing about the Zend engine
 specific. 

The mentioned place is directly in the VM, which in general is harder to
understand, but well, it directs to the concat_function on
http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_operators.c#1234

Knowing basic C should be enough to understand the code there. The
actual algorithm can also easily be guessed (allocate a buffer which
can hold both strings at once and copy them over,the code is a tiny bit
more complex as it tries tore use an existing buffer than allocating
something completely new)

The question is: What do you actually want to know?

 Can you point me to some resources on this topic?

Unfortunately not. The source is the best documentation we have for
that.

johannes



-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-DEV] concatenation operator

2012-06-05 Thread Adi Mutu


Hello,

Can somebody point me to where the concatenation operator is implemented ?  . 
operator.

Thanks,


Re: [PHP-DEV] ZEND_MM_SMALL_FREE_BUCKET and ZEND_MM_REST_BUCKET

2012-03-02 Thread Adi Mutu


Thanks Julien,

but i've already read your article using translator and did not found an answer 
to that (i've also sent you an email about Zend mm a few days ago)
laurence site looks down to me. Perhaps the link is wrong?

Thanks,
A.



 From: jpauli jpa...@php.net
To: Adi Mutu adi_mut...@yahoo.com 
Cc: internals@lists.php.net internals@lists.php.net 
Sent: Friday, March 2, 2012 3:43 PM
Subject: Re: [PHP-DEV] ZEND_MM_SMALL_FREE_BUCKET and ZEND_MM_REST_BUCKET
 
Laruence and I wrote articles about ZendMM internals.

You would find them at http://www.laruence.com/2011/11/09/2277.html and
http://julien-pauli.developpez.com/tutoriels/php/internals/zend-memory-manager/
.
You can use any translator to get them in English

For basic use, see the readme at
http://lxr.php.net/xref/PHP_5_4/Zend/README.ZEND_MM

Hope this helps :)

Julien.P

On Fri, Mar 2, 2012 at 1:51 PM, Adi Mutu adi_mut...@yahoo.com wrote:



 Hello,

 Can somebody shed some light on these 2 defines? Thanks.


 #define ZEND_MM_SMALL_FREE_BUCKET(heap, index) \ (zend_mm_free_block*)
 ((char*)heap-free_buckets[index * 2] + \     sizeof(zend_mm_free_block*)
 * 2 - \      sizeof(zend_mm_small_free_block))      #define
 ZEND_MM_REST_BUCKET(heap) \
 (zend_mm_free_block*)((char*)heap-rest_buckets[0] + \
 sizeof(zend_mm_free_block*) * 2 - \      sizeof(zend_mm_small_free_block))

Re: [PHP-DEV] ZEND_MM_SMALL_FREE_BUCKET and ZEND_MM_REST_BUCKET

2012-03-02 Thread Adi Mutu
Now that's really awesome.:)
I have to do something so i can access and subscribe to that blog.
Are you serious about that firewall?
That would be my first time i actually encounter a problem because of this.



 From: Ferenc Kovacs tyr...@gmail.com
To: Adi Mutu adi_mut...@yahoo.com 
Cc: jpauli jpa...@php.net; internals@lists.php.net 
internals@lists.php.net 
Sent: Friday, March 2, 2012 4:00 PM
Subject: Re: [PHP-DEV] ZEND_MM_SMALL_FREE_BUCKET and ZEND_MM_REST_BUCKET
 




On Fri, Mar 2, 2012 at 2:57 PM, Adi Mutu adi_mut...@yahoo.com wrote:



Thanks Julien,

but i've already read your article using translator and did not found an 
answer to that (i've also sent you an email about Zend mm a few days ago)
laurence site looks down to me. Perhaps the link is wrong?

Thanks,
A.





I blame the Great Firewall of China
could you try that the following link works for you:
http://translate.google.com/translate?sl=zh-CNtl=enjs=nprev=_thl=huie=UTF-8layout=2eotf=1u=http%3A%2F%2Fwww.laruence.com%2F2011%2F11%2F09%2F2277.html
 
 
-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

Re: [PHP-DEV] ZEND_MM_SMALL_FREE_BUCKET and ZEND_MM_REST_BUCKET

2012-03-02 Thread Adi Mutu


Already added in google reader..now i see the site is accesible also, 
strange.

I've looked at the picture, read your explanation, but i still didn't get 
it.i'll think some more about this and perhaps i'll suggest you a better 
translation at the end.

Thanks!



 From: Laruence larue...@php.net
To: Adi Mutu adi_mut...@yahoo.com 
Cc: Ferenc Kovacs tyr...@gmail.com; jpauli jpa...@php.net; 
internals@lists.php.net internals@lists.php.net 
Sent: Friday, March 2, 2012 4:52 PM
Subject: Re: [PHP-DEV] ZEND_MM_SMALL_FREE_BUCKET and ZEND_MM_REST_BUCKET
 
On Fri, Mar 2, 2012 at 10:12 PM, Adi Mutu adi_mut...@yahoo.com wrote:
 Now that's really awesome.:)
 I have to do something so i can access and subscribe to that blog.
Hi:

Google reader is a good choice~ :)

I am so glad you like it.

thanks .
 Are you serious about that firewall?
 That would be my first time i actually encounter a problem because of this.


 
  From: Ferenc Kovacs tyr...@gmail.com
 To: Adi Mutu adi_mut...@yahoo.com
 Cc: jpauli jpa...@php.net; internals@lists.php.net 
 internals@lists.php.net
 Sent: Friday, March 2, 2012 4:00 PM
 Subject: Re: [PHP-DEV] ZEND_MM_SMALL_FREE_BUCKET and ZEND_MM_REST_BUCKET





 On Fri, Mar 2, 2012 at 2:57 PM, Adi Mutu adi_mut...@yahoo.com wrote:



Thanks Julien,

but i've already read your article using translator and did not found an 
answer to that (i've also sent you an email about Zend mm a few days ago)
laurence site looks down to me. Perhaps the link is wrong?

Thanks,
A.





 I blame the Great Firewall of China
 could you try that the following link works for you:
 http://translate.google.com/translate?sl=zh-CNtl=enjs=nprev=_thl=huie=UTF-8layout=2eotf=1u=http%3A%2F%2Fwww.laruence.com%2F2011%2F11%2F09%2F2277.html

 --
 Ferenc Kovács
 @Tyr43l - http://tyrael.hu



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

Re: [PHP-DEV] ZEND_MM_SMALL_FREE_BUCKET and ZEND_MM_REST_BUCKET

2012-03-02 Thread Adi Mutu



I think that caching part you're talking about is in function 
zend_mm_alloc_int..i don't see what caching has to do with these macros...
but i maybe mistaking of course. What i don't understand is those additions and 
substracting in those macros..but i'll read more tomorrow.



 From: Stas Malyshev smalys...@sugarcrm.com
To: Adi Mutu adi_mut...@yahoo.com 
Cc: internals@lists.php.net internals@lists.php.net 
Sent: Friday, March 2, 2012 8:44 PM
Subject: Re: [PHP-DEV] ZEND_MM_SMALL_FREE_BUCKET  and ZEND_MM_REST_BUCKET
 
Hi!

 
 #define ZEND_MM_SMALL_FREE_BUCKET(heap, index) \
 (zend_mm_free_block*) ((char*)heap-free_buckets[index * 2] + \
 sizeof(zend_mm_free_block*) * 2 - \
 sizeof(zend_mm_small_free_block))
 #define
 ZEND_MM_REST_BUCKET(heap) \
 (zend_mm_free_block*)((char*)heap-rest_buckets[0] + \
 sizeof(zend_mm_free_block*) * 2 - \
 sizeof(zend_mm_small_free_block))

IIRC the purpose of these defines is that the MM caches small free blocks so 
that it could find them faster, so that for example allocating zvals (frequent 
case) goes faster. So it has a small cache for such blocks, by size, so the 
allocator can for example quickly find a free block of size of zval or of size 
of Hashtable. These macros try to find such free block for given small size 
(first one) or for the rest of blocks (i.e. bigger blocks which share one free 
list).
-- Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

-- PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-DEV] question about Zend MM

2012-03-01 Thread Adi Mutu


Hello,

I want to understand how Zend MM works, so i'm looking trought the sources and 
i see this:

#define ZEND_MM_ALIGNMENT_MASK ~(ZEND_MM_ALIGNMENT-1) #define 
ZEND_MM_ALIGNED_SIZE(size)(((size) + ZEND_MM_ALIGNMENT - 1)  
ZEND_MM_ALIGNMENT_MASK) 


I understand that the first define will create something like 1000 ( it 
will clear last 3 bits)
but what does the 2nd define? Before clearing the last 3 bytes why does it add 
ZEND_MM_ALIGNMENT- 1
to size?

Thanks,

Re: [PHP-DEV] question about Zend MM

2012-03-01 Thread Adi Mutu



Ah, now i got it..so it can also return size, if size is directly a 
multiple of  ZEND_MM_ALIGNMENT.
I was convinced that it has to be stricly  than size, i guess i was wrong.



 From: Gustavo Lopes glo...@nebm.ist.utl.pt
To: Adi Mutu adi_mut...@yahoo.com; internals@lists.php.net 
Sent: Thursday, March 1, 2012 6:44 PM
Subject: Re: [PHP-DEV] question about Zend MM 
 
On Thu, 01 Mar 2012 17:22:23 +0100, Adi Mutu adi_mut...@yahoo.com wrote:

 I want to understand how Zend MM works, so i'm looking trought the sources 
 and i see this:
 
 #define ZEND_MM_ALIGNMENT_MASK ~(ZEND_MM_ALIGNMENT-1) #define 
 ZEND_MM_ALIGNED_SIZE(size)    (((size) + ZEND_MM_ALIGNMENT - 1)  
 ZEND_MM_ALIGNMENT_MASK)
 
 
 I understand that the first define will create something like 1000 ( it 
 will clear last 3 bits)
 but what does the 2nd define? Before clearing the last 3 bytes why does it 
 add ZEND_MM_ALIGNMENT- 1
 to size?
 

It basically just rounds to the next multiple of ZEND_MM_ALIGNMENT, assuming 
ZEND_MM_ALIGNMENT is a power of 2.

ZEND_MM_ALIGNMENT is a power of 2, so it has 1 bit set. Subtracting 1 will zero 
that bit and and flip on all the other less significant bits. Then negating 
flips the bits so that now the bits less significant than the 
log2(ZEND_MM_ALIGNMENT)-th will be zero and the others will be one.

ZEND_MM_ALIGNED_SIZE adds ZEND_MM_ALIGNMENT - 1 and applies the mask. The 
effect is that the result will be = size and it will be a multiple of 
ZEND_MM_ALIGNMENT (in particular the smallest multiple of ZEND_MM_ALIGNMENT 
that's = the argument) because the bits less significant than the 
log2(ZEND_MM_ALIGNMENT)-th will be zero. a  n-1 is the same as a mod n 
with n being a power of 2. So if a  ZEND_MM_ALIGNMENT - 1 == 0 then a mod 
ZEND_MM_ALIGNMENT == 0 and a is a multiple of ZEND_MM_ALIGNMENT.

--Gustavo Lopes

Re: [PHP-DEV] how to debug a php script ( the C code beneath it)

2012-02-14 Thread Adi Mutu
Thanks Julien

I don't know french, but i'll read it using google translate:)



 From: jpauli jpa...@php.net
To: Adi Mutu adi_mut...@yahoo.com 
Cc: Ángel González keis...@gmail.com; PHP Developers Mailing List 
internals@lists.php.net 
Sent: Tuesday, February 14, 2012 11:17 AM
Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)
 
2012/2/14 Adi Mutu adi_mut...@yahoo.com

 Perhaps i didn't explain correctly, my bad, sorry.
 Basically what I want to see is the corresponding C code which is
 executed, i could put a break in gdb, but how do I know at which C function
 to put it, if i don't know the internals of php very good?


And the answer is : you cant.
Simply put, you have to study the code first, before knowing through which
line it will go.
That's not very easy, as you can count on ~800.000 lines in trunk.

To see the path, use valgrind + callgrind. You'll get a very cool graph
like this :
http://julien-pauli.developpez.com/tutoriels/php/internals/presentation/images/PHPInternals-callgraph.png

You could use gdb with the .gdbinit from trunk. Using it with CDT is much
more cool as it is GUI.

I wrote some article about PHP internals, mainly describing how it works.
It's in french (
http://julien-pauli.developpez.com/tutoriels/php/internals/presentation)
with some schema.

Mainly, the hardest part is ZendVM. If you dont have to debug ZendVM, it's
kinda easy and logic.

Cheers

Julien.Pauli




 
  From: Ángel González keis...@gmail.com
 To: Adi Mutu adi_mut...@yahoo.com
 Cc: PHP Developers Mailing List internals@lists.php.net
 Sent: Tuesday, February 14, 2012 1:11 AM
 Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)

 On 13/02/12 21:48, Adi Mutu wrote:
  Hello,
 
  Perhaps this is a stupid question, but i haven't coded in C in years and
 i'm not very familiar with development/debugging tools. If I have a php
 script say 20 lines,
  How can I see a path of the corresponding C code which is executed? What
 If i would like to break at a certain php line in the script, is it
 possible?
 
  Thanks,
 Why do you want to do it?
 It looks to me like that you are trying to solve a problem the hard way
 by doing that.


Re: [PHP-DEV] how to debug a php script ( the C code beneath it)

2012-02-14 Thread Adi Mutu


I know about the zif_* functions and i'm already using lxr.php.net.
Didn't know about Gcc -e trick though, that might be usefull.

Thanks.



 From: jpauli jpa...@php.net
To: Rasmus Lerdorf ras...@php.net 
Cc: Adi Mutu adi_mut...@yahoo.com; PHP Developers Mailing List 
internals@lists.php.net 
Sent: Tuesday, February 14, 2012 7:36 PM
Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)
 
On Tue, Feb 14, 2012 at 6:28 PM, Rasmus Lerdorf ras...@php.net wrote:

 On 02/14/2012 09:22 AM, Adi Mutu wrote:
  Thanks Julien
 
  I don't know french, but i'll read it using google translate:)

 If you just want to see some of the function calls, most calls that are
 visible in userspace are prefixed with zif_ internally.

 eg.

 % gdb sapi/cli/php
 GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
 ...
 (gdb) b zif_strlen
 Breakpoint 1 at 0x7b2760: file
 /home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c,
 line 455.
 (gdb) run -r 'echo strlen(123);'
 Breakpoint 1, zif_strlen (ht=1, return_value=0x1200eb0,
 return_value_ptr=0x0, this_ptr=0x0, return_value_used=1)
    at
 /home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c:455
 455     {
 (gdb) l
 450
 451
 452     /* {{{ proto int strlen(string str)
 453        Get string length */
 454     ZEND_FUNCTION(strlen)
 455     {
 456             char *s1;
 457             int s1_len;

 -Rasmus

 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php


Yeah, that's the PHP_FUNCTION() macro. 'zif' meaning Zend Internal
Function.
One more step would be to read the preprocessed code (GCC -E), as PHP
source heavily uses macros

If you want, you can also read the source code online using the excellent
http://lxr.php.net :)

Julien.P

Re: [PHP-DEV] how to debug a php script ( the C code beneath it)

2012-02-14 Thread Adi Mutu
I know about the zif_* functions and i'm already using lxr.php.net.
Didn't know about gcc -E trick though, that might be usefull.

Thanks.



 From: jpauli jpa...@php.net
To: Rasmus Lerdorf ras...@php.net 
Cc: Adi Mutu adi_mut...@yahoo.com; PHP Developers Mailing List 
internals@lists.php.net 
Sent: Tuesday, February 14, 2012 7:36 PM
Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)
 

On Tue, Feb 14, 2012 at 6:28 PM, Rasmus Lerdorf ras...@php.net wrote:

On 02/14/2012 09:22 AM, Adi Mutu wrote:
 Thanks Julien

 I don't know french, but i'll read it using google translate:)

If you just want to see some of the function calls, most calls that are
visible in userspace are prefixed with zif_ internally.

eg.

% gdb sapi/cli/php
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
...
(gdb) b zif_strlen
Breakpoint 1 at 0x7b2760: file
/home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c,
line 455.
(gdb) run -r 'echo strlen(123);'
Breakpoint 1, zif_strlen (ht=1, return_value=0x1200eb0,
return_value_ptr=0x0, this_ptr=0x0, return_value_used=1)
   at
/home/rasmus/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c:455
455     {
(gdb) l
450
451
452     /* {{{ proto int strlen(string str)
453        Get string length */
454     ZEND_FUNCTION(strlen)
455     {
456             char *s1;
457             int s1_len;

-Rasmus


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Yeah, that's the PHP_FUNCTION() macro. 'zif' meaning Zend Internal Function.
One more step would be to read the preprocessed code (GCC -E), as PHP 
source heavily uses macros

If you want, you can also read the source code online using the excellent 
http://lxr.php.net :)

Julien.P

[PHP-DEV] how to debug a php script ( the C code beneath it)

2012-02-13 Thread Adi Mutu



Hello,

Perhaps this is a stupid question, but i haven't coded in C in years and i'm 
not very familiar with development/debugging tools. If I have a php script say 
20 lines,
How can I see a path of the corresponding C code which is executed? What If i 
would like to break at a certain php line in the script, is it possible?

Thanks,

Re: [PHP-DEV] how to debug a php script ( the C code beneath it)

2012-02-13 Thread Adi Mutu
Perhaps i didn't explain correctly, my bad, sorry.
Basically what I want to see is the corresponding C code which is executed, i 
could put a break in gdb, but how do I know at which C function to put it, if i 
don't know the internals of php very good?



 From: Ángel González keis...@gmail.com
To: Adi Mutu adi_mut...@yahoo.com 
Cc: PHP Developers Mailing List internals@lists.php.net 
Sent: Tuesday, February 14, 2012 1:11 AM
Subject: Re: [PHP-DEV] how to debug a php script ( the C code beneath it)
 
On 13/02/12 21:48, Adi Mutu wrote:
 Hello,

 Perhaps this is a stupid question, but i haven't coded in C in years and i'm 
 not very familiar with development/debugging tools. If I have a php script 
 say 20 lines,
 How can I see a path of the corresponding C code which is executed? What If i 
 would like to break at a certain php line in the script, is it possible?

 Thanks,
Why do you want to do it?
It looks to me like that you are trying to solve a problem the hard way
by doing that.

[PHP-DEV] zend guard

2012-01-30 Thread Adi Mutu
Hello,

Can anybody tell me what this struct is used for ?
I'm new to the internals of php.

Thanks,
A


Re: [PHP-DEV] Re: Zend mm

2011-02-01 Thread Adi Mutu

Thanks a lot, for all the help about zend mm guys,  i'm very grateful.
Thanks,A.

--- On Sun, 1/30/11, Ben Schmidt mail_ben_schm...@yahoo.com.au wrote:

From: Ben Schmidt mail_ben_schm...@yahoo.com.au
Subject: Re: [PHP-DEV] Re: Zend mm
To: Adi Mutu adi_mut...@yahoo.com
Cc: internals@lists.php.net, t...@daylessday.org
Date: Sunday, January 30, 2011, 4:45 PM

On 30/01/11 4:11 AM, Adi Mutu wrote:
 I have looked at the sources, but i'm only at the begining of
 analyzing the php sources.i've understand how to write extensions
 for example, but this memory manager seems more complicated to me.

Yes, it is. Memory management is a low-level and subtle area. It takes a
lot of careful thought to design and even to understand the algorithms
involved. It is hard to debug, because an error caused in one place may
not show itself until completely different code is executing. It is also
an area which doesn't change much. Almost all the other code in the PHP
interpreter, and therefore PHP scripts themselves, rely on the memory
manager code doing its job unintrusively and correctly, so once it is
working well, it tends to be left that way, except for fixing small bugs
as they are found, or a big and careful development effort to address
some limitation (e.g. improving the garbage collection to collect
cycles, which was something done fairly recently).

The bottom line is that this is not an area that is all that easy for
beginners to get their teeth into. But it's also an area that isn't
necessary for beginners to understand in much detail, either. Unless you
have a particular project in mind that involves the memory manager, you
probably don't need to touch it.

I don't want to discourage you, but just point out that perhaps this is
something you might look at later, or even not at all, as you may find
there are many worthwhile projects that take up all your time before you
ever get to understanding the memory manager fully.

 It would be useful if for example, could explain me the structures
 that are used in the Zend memory manager, how they're chained
 etc.and if you can tell me in words what do zend_mm_aloc_int() and
 zend_mm_free_int() basically do...Thank you for your time,Adrian

I suspect these structures and functions are fairly easy to understand
by someone familiar with the area of memory management, which is why you
have been advised to consult the source code. So perhaps what you need
to do is not learn about PHP's memory manager, but just learn about
memory management in general. Then it should be fairly easy to
understand what PHP's memory manager is doing from its code.

I'm afraid I doubt the people here have the time to teach you this over
email. :-) So here are some references which might be of use to you.

- I believe the 'standard textbook' for learning about memory management
  is this one here:
  http://www.cs.kent.ac.uk/people/staff/rej/gcbook/gcbook.html

- This page also mentions that a new edition is due out soon:
  http://c2.com/cgi/wiki?GarbageCollectionBook

- You can also check out this site: http://www.memorymanagement.org/

- Relating this to, PHP: PHP is a garbage collected language which I
  believe uses reference counting and a clever collector to detect and
  free cycles. I haven't looked in detail into the implementation, but I
  know some documentation is available on the subject here:
  http://www.php.net/manual/en/features.gc.php

Hope this helps!

Ben.






  

[PHP-DEV] Re: Zend mm

2011-01-29 Thread Adi Mutu

I have looked at the sources, but i'm only at the begining of analyzing the php 
sources.i've understand how to write extensions for example, but this 
memory manager seems more complicated to me.
It would be useful if for example, could explain me the structures that are 
used in the Zend memory manager, how they're chained etc.and if you can 
tell me in words what do zend_mm_aloc_int() and zend_mm_free_int() basically 
do...Thank you for your time,Adrian  


  

[PHP-DEV] Zend mm

2011-01-27 Thread Adi Mutu
Hello,

Nobody can help me understand better the internals of the zend memory manager?

Thanks,Adrian




  

[PHP-DEV] zend memory manager

2011-01-24 Thread Adi Mutu
Hello,

Where can I find some references to read about the Zend 
mm? I'm not talking about emalloc/efree (or pemalloc/pefree), i'm 
talking about lower level functions like zend_mm_aloc_int and 
zend_mm_free_int, structs like zend_mm_heap etc.I've tried looking 
at the sources, but it's not very clear for meI'm a beginner at php C
 developing.

Thanks,