Questions tagged [php-internals]

How the PHP programming language works underneath, and questions about the underlying C code.

PHP Internals

Tag purpose

The purpose of the tag is to indicate a question about the internals of PHP. Possible questions could be about how references counting or copy on write. E.g. When you want to know what happens under the hood while doing things in PHP. It can also be applied to questions in the tag that deal with extending PHP at the core. This tag should also be used for any questions about the Zend Engine powering PHP.


External Links

269 questions
8
votes
3 answers

puzzling php parser error

Ok maybe not so puzzling, but here it is. I was messing around and noticed this, typing just
frostymarvelous
  • 2,786
  • 32
  • 43
8
votes
3 answers

Duplicate array keys (Notice: member variable "a" returned from __sleep() multiple times)

The title may seem a bit silly but I'm totally serious with this. Today at work I came across a weird PHP behaviour which I could not explain. Luckily this behaviour is fixed in PHP 7.4, so it seems that someone stumbled upon that, too. I made a…
Benjamin Paap
  • 2,744
  • 2
  • 21
  • 33
8
votes
3 answers

How do I compile a PHP extension with Microsoft Visual C++ 2008?

I created a PHP Hello World extension DLL with Microsoft Visual C++ 2008. I have the right php.ini (I know because when I enable and disable the gd2 extension, there is an effect), but when I load the extension it does not pop up under the…
Mark Lalor
  • 7,820
  • 18
  • 67
  • 106
8
votes
2 answers

What is the difference between Mysqlnd, PDO and PDO_Mysql extensions in php?

They seem to be the same thing, and yet different. I don't know which one is which: I know we can use PDO as new PDO() and use prepare() and query() methods, to fetch data from database. So, if this is PDO mentioned in the extensions list, then what…
ʎɹnɔɹǝW
  • 811
  • 2
  • 8
  • 14
8
votes
6 answers

PHP Performance : Copy vs. Reference

Hey there. Today I wrote a small benchmark script to compare performance of copying variables vs. creating references to them. I was expecting, that creating references to large arrays for example would be significantly slower than copying the whole…
fresskoma
  • 25,481
  • 10
  • 85
  • 128
8
votes
1 answer

PHP Generators - Garbage Collection

Simple question. When or how, by PHP or yourself do generators destroy their stacks? Take the following example: function doWork(): Generator { // create some objects. $o1 = new stdClass(); $o2 = new stdClass(); // pause here and…
Flosculus
  • 6,880
  • 3
  • 18
  • 42
8
votes
3 answers

How to return array from a PHP extension, without copying it in memory?

I'm developing a PHP-extension, where an object method needs to return an array zval. The method looks like: ZEND_METHOD(myObject, myMethod) { zval **myArrayProperty; if (zend_hash_find(Z_OBJPROP_P(getThis()), "myArrayProperty",…
Andrey Tserkus
  • 3,644
  • 17
  • 24
8
votes
2 answers

SEG Fault in PHP extension

I wrote a PHP extension to access functions in a static lib, I built PHP as a CGI, and everything seemed to work (after days of working on it..) Thrilled once everything worked, I re-compiled PHP without debugging messages I had in it.…
Matt
  • 1,928
  • 24
  • 44
7
votes
3 answers

Why is file_get_contents faster than memcache_get?

I'm loading XML files from disk using file_get_contents, and as a test I find I can load a 156K file using file_get_contents() 1,000 times in 3.99 seconds. I've subclassed the part that does the loading and replaced it with a memcache layer, and on…
halfer
  • 19,824
  • 17
  • 99
  • 186
7
votes
1 answer

Why `mysqli_query()` returns null? How can i figure it out?

Under certain circumstances, the built-in function in PHP called mysqli_query returns null. Such behaviour is not foreseen by the function's documentation that explains how to use it, so I tried to dive in PHP's source code itself, posted on GitHub,…
SebasSBM
  • 860
  • 2
  • 8
  • 32
7
votes
1 answer

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

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…
Jürgen Thelen
  • 12,745
  • 7
  • 52
  • 71
6
votes
4 answers

PHP Internals: How does TSRMLS_FETCH Work?

How does the PHP Internals TSRMLS_FETCH macro do its job? Per the PHP Manual While developing extensions, build errors that contain "tsrm_ls is undefined" or errors to that effect stem from the fact that TSRMLS is undefined in the current scope, to…
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
6
votes
8 answers

Compare PHP Arrays Using Memory References

Is it possible to see if two array variables point to the same memory location? (they are the same array)
Kirk Ouimet
  • 27,280
  • 43
  • 127
  • 177
6
votes
2 answers

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

We have a piece of simple code: 1
srain
  • 8,944
  • 6
  • 30
  • 42
6
votes
2 answers

Zend: How to correctly destruct a custom object in PHP 7?

I'm learning PHP extension writing in order to make some old extensions work with PHP 7. I tried to modify the sample extension from http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-extension/ but it kept causing segfaults when destructing…
Frederick Zhang
  • 3,593
  • 4
  • 32
  • 54