php-internals

PHP: Copy On Write and Assign By Reference perform different on PHP5 and PHP7

我的梦境 提交于 2019-11-30 05:14:16
问题 We have a piece of simple code: 1 <?php 2 $i = 2; 3 $j = &$i; 4 echo (++$i) + (++$i); On PHP5, it outputs 8, because: $i is a reference, when we increase $i by ++i , it will change the zval rather than make a copy, so line 4 will be 4 + 4 = 8 . This is Assign By Reference . If we comment line 3, it will output 7, every time we change the value by increasing it, PHP will make a copy, line 4 will be 3 + 4 = 7 . This is Copy On Write . But in PHP7, it always outputs 7. I've checked the changes

Do unused use statements decrease performance?

别来无恙 提交于 2019-11-30 01:54:56
问题 I want to know if unused use statements in my class affect performance of my php website? Does php include all classes in beginning or when need it? If second choice then I think it doesn't affect performance of my system. For Example: Use statement 'DbConnector' is not used use model\adapter\DbConnector; 回答1: No, the use statement does not provoke the the class be loaded (it does not even trigger an autoloader). It just declares a short name for a class. I assume the cost in terms of CPU and

Linking a PHP Extension Written in C

☆樱花仙子☆ 提交于 2019-11-29 23:56:47
问题 Edit: Revising My Question When building an external PHP module in C, how do I link shared objects? 回答1: If your C extension code uses a shared library, you need to declare that in the config.m4 file. I strongly recommend using the ext_skel script that's included in the PHP source to generate a skeleton config.m4: ./ext_skel --extname=myextension Since you're linking to a library, by convention you should use the --with-myextension options (as opposed to --enable-myextension ). Uncomment the

What's the Difference Between Extension and zend_extension in php.ini?

你离开我真会死。 提交于 2019-11-29 23:38:09
When I installed Xdebug through pecl , it added the following line to my php.ini file. extension="xdebug.so" and everything I used worked. Until today. Today I was having trouble setting up Xdebug for interactive debugging. I couldn't get anything working until I changed the above to zend_extension="/usr/local/lib/php/extensions/xdebug.so" (Caveat: I think this is what got me working, but I'm not 100% sure) This raised the question in my mind. What's the difference in loading an extension via extension= vs. zend_extension ? Milen A. Radev At the core of the PHP language (more like the

Capturing (externally) the memory consumption of a given Callback

戏子无情 提交于 2019-11-29 15:54:31
The Problem Lets say I have this function: function hog($i = 1) // uses $i * 0.5 MiB, returns $i * 0.25 MiB { $s = str_repeat('a', $i * 1024 * 512); return substr($s, $i * 1024 * 256); } I would like to call it and be able to inspect the maximum amount of memory it uses. In other words: memory_get_function_peak_usage($callback); . Is this possible? What I Have Tried I'm using the following values as my non-monotonically increasing $i argument for hog() : $iterations = array_merge(range(0, 50, 10), range(50, 0, 5)); $iterations = array_fill_keys($iterations, 0); Which is essentially: ( [0] => 0

how to write PHP module in C

放肆的年华 提交于 2019-11-29 06:24:22
问题 how can i write my own module in C ? is it possible ? 回答1: Yes, it is possible. Here's an old article that I used when I wrote my first extension: http://web.archive.org/web/20110222035803/http://devzone.zend.com/article/1021 Things may have changed since then, so you may want to search for similar tutorials for additional references. Oh, and this should be useful: http://www.php.net/manual/en/internals2.php 来源: https://stackoverflow.com/questions/5631231/how-to-write-php-module-in-c

How does PHP assign and free memory for variables?

自作多情 提交于 2019-11-28 23:38:37
I was wondering when does PHP free the memory which is used for a variables for example function foo(){ $foo = 'data'; return $foo; // <- is the memory space for `$foo` emptied at this point? } is it slower than: function foo(){ return 'data'; } ? Well, let's find out! <?php $checkpoints = array( 'start' => memory_get_usage() ); $checkpoints['before defining demo1'] = memory_get_usage(); function demo1() { $foo = 'data'; return $foo; } $checkpoints['after defining demo1'] = memory_get_usage(); $checkpoints['before defining demo2'] = memory_get_usage(); function demo2() { return 'data'; }

Reading Zend Engine API code: What does ## (double hash) mean?

我是研究僧i 提交于 2019-11-28 23:09:00
Out of curiousity, I'm reading the Zend Engine API code and encountered quite a number of ## in their #define's. For example, at /usr/lib/php5/Zend/zend_API.h: #define ZEND_FN(name) zif_##name #define ZEND_MN(name) zim_##name What does the ## (double hash) symbols mean in these two lines? The ## concatenates what's before the ## with what's after it. So in your example doing ZEND_FN(foo) would result in zif_foo Echo RvV's answer. Be aware that when concatenating literal strings you may find some inconsistencies between pre-processors/compilers. Some will require the ## #define STR_CAT(s1, s2)

How does PHP memory actually work

谁说胖子不能爱 提交于 2019-11-28 21:15:01
I've always heard and searched for new php 'good writing practice', for example: It's better (for performance) to check if array key exists than search in array, but also it seems better for memory too: Assuming we have: $array = array ( 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, ); this allocates 1040 bytes of memory, and $array = array ( 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', ); requires 1136 bytes I understand that the key and value surely will have different storing mechanism, but please can you actually point me to the principle how does it work? Example 2 (for

Where can I learn about PHP internals? [closed]

≯℡__Kan透↙ 提交于 2019-11-28 02:55:52
What are good resources to start learning the internals of PHP and the Zend Engine? The PHP Manual has a (sadly mostly empty) chapter on PHP internals . The main development mailing list is internals@lists.php.net. You can sign up via php.net and/or use Markmail to search the archives . The git repository for PHP is located on git.php.net , but there is also a mirror on GitHub . For browsing the source code you should use the lxr.php.net cross reference tool . The PHP wiki has a list of various resources on PHP development (blog posts, books, slides, etc). In particular there is an (older)