php-internals

Getting Started with PHP Extension-Development [closed]

余生长醉 提交于 2019-12-17 07:15:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Please suggest help articles or tutorials about PHP "low" level С-modules programming interface. 回答1: Searching through my bookmarks, only links I found are those : Extension Writing Part I: Introduction to PHP and Zend Extension Writing Part II: Parameters, Arrays, and ZVALs Extension Writing Part II:

Which is faster between (string)$value and “$value” when casting to a string

放肆的年华 提交于 2019-12-12 20:17:33
问题 In PHP, assuming $value = 12345; (an integer), which is faster when casting $value from an integer to a string; $value = (string)$value; or $value = "$value"; This is a kind of performance measure question and specifically for this case. Thanks for your help! 回答1: Your question is really about the efficacy of the php interpreter, and how it converts php code (the one you write) to php bytecode (the one that runs and may actually consume time and resources). If i take p01ymath's experiment,

Why is Importing a PHP Function into the Current Namespace Unsupported

怎甘沉沦 提交于 2019-12-12 09:39:08
问题 According to the PHP documentation PHP namespaces support three kinds of aliasing or importing: aliasing a class name, aliasing an interface name, and aliasing a namespace name. Note that importing a function or constant is not supported. Does anyone know the historical or technical context of why importing a function or constant is unsupported? 回答1: I contacted Jochem Maas (the author of this five year old RFC), and while he was hesitant to pin point a single reason (understandably, as he

Where to find the “low memory” and “free CPU cycles” calls triggering garbage collection on unset()?

谁都会走 提交于 2019-12-12 08:44:03
问题 I often find references to the following quote being used when explaining that a PHP unset() doesn't trigger "garbage collection" immediately, but only when it sees fit (emphasis mine): unset() does just what it's name says - unset a variable. It does not force immediate memory freeing. PHP's garbage collector will do it when it see fits - by intention as soon, as those CPU cycles aren't needed anyway, or as late as before the script would run out of memory , whatever occurs first. If you are

PHP-FPM pool status of process last-request-cpu

陌路散爱 提交于 2019-12-11 03:07:27
问题 I have installed a PHP and enable the FPM function, but i feel uncertain about the FPM status data(like the process last-request-cpu), below is my php-fpm.conf detail. [www] ; Unix user/group of processes user = www-data group = www-data ; Chdir to this directory at the start. chdir = / ; The address on which to accept FastCGI requests. listen = /var/run/phpfpm/$pool_php5-fpm.sock ; Set listen(2) backlog. A value of '-1' means unlimited. listen.backlog = -1 ; Set permissions for unix socket.

PHP Zend Engine Extension and static methods

≯℡__Kan透↙ 提交于 2019-12-10 17:43:53
问题 On writing an extension for php (5.3) i want to access the zend_class_entry pointer on a static method. On non static methods i can use the getThis() macro and within Z_OBJCE_P macro like this: zend_class_entry ce* = Z_OBJCE_P(getThis()); Now the problem: on static methods the getThis() macro returns a null pointer, so i can not use the Z_OBJCE_P macro. Has anyone a solution for me to access the zend_class_entry from a static method?? 回答1: it is really interesting: on static methods you can

Increasing array elements while in foreach loop in php? [duplicate]

℡╲_俬逩灬. 提交于 2019-12-10 14:54:18
问题 This question already has answers here : How does PHP 'foreach' actually work? (7 answers) Closed 5 years ago . Consider the code below: <?php $arr = array(); $arr['b'] = 'book'; foreach($arr as $key=>$val) { print "key=>$key\n"; if(!isset($arr['a'])) $arr['a'] = 'apple'; } ?> It is not displaying 'a'. How foreach works with hash-table(array), to traverse each element. If lists are implement why can't I add more at run time ? Please don't tell me that I could do this task with numeric based

Why does foreach copy the array when we did not modify it in the loop? [duplicate]

北城以北 提交于 2019-12-10 01:20:42
问题 This question already has answers here : How does PHP 'foreach' actually work? (7 answers) Closed 6 years ago . In a blog post "PHP Internals: When does foreach copy", NikiC stated that in a code like this: Snippet 1 $array = range(0, 100000); foreach ($array as $key => $value) { xdebug_debug_zval('array'); // array is not copied, only refcount is increased } foreach will not copy the array because the only thing that foreach modifies about $array is it's internal array pointer. He also

Is the Zend engine embeddable outside of PHP?

橙三吉。 提交于 2019-12-07 08:00:52
问题 One of the original designs of the Zend engine, if I recall, was that it was to be relatively easy to embed for other languages one might wish to create. Basically, the PHP syntax without all the PHP modules. Is this still the case? 回答1: Well, the Zend Engine is basically a Virtual Machine that interprets PHP bytecode. Basically what you would have to do is create a parser for a language and a compiler and have it compile it into PHP bytecode therefore it could be executed by the Zend Engine.

How do I add an array as an Object Property to a class declared within a PHP extension?

点点圈 提交于 2019-12-06 05:13:42
问题 I want my PHP extension to declare a class equivalent to the following PHP: class MyClass { public $MyMemberArray; __construct() { $this->MyMemberArray = array(); } } I'm following the examples in "Advanced PHP Programming" and "Extending and Embedding PHP" and I'm able to declare a class that has integer properties in PHP_MINIT_FUNCTION . However, when I use the same approach to declare an array property in PHP_MINIT_FUNCTION , I get the following error message at runtime: PHP Fatal error: