All Questions
Tagged with zend-engine or php-internals
270 questions
15
votes
3
answers
2k
views
Returning "Native" PHP Objects from an Extension
I'm dabbling with creating a PHP extension for a personal project. Beyond what's linked in the above article I have no knowledge of the zend_engine, and my C skills are 10 years out of date, and were ...
7
votes
3
answers
2k
views
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 ...
3
votes
1
answer
655
views
php extension: can not update class field using zend_hash_update
I want to realize this class into php extension:
class MyClass {
protected $attrs = array();
public function __construct($id = null) {
$this->attrs['id'] = $id;
$this->attrs['name'] ...
4
votes
1
answer
653
views
How to overload functions from a PHP extension?
I've been going through some PHP extension tutorials, but I can't find any information about how to overload existing function.
For example, I want to change the fopen() to something like
...
13
votes
2
answers
4k
views
What is #<some-number> next to object(someClass) in var_dump of an object? I have an inference. Am I right?
This is the code & its output I used to draw the inference below:
class a {
public $var1;
public $var2;
}
$obj0 = new a;
var_dump($obj0);
class b {
public $var1;
public $...
1
vote
1
answer
115
views
Why C.O.W does not take place when ' writing to a property ' / ' injecting a property into an object ' of class?
class a {
public $test="msg1";
}
$t1 = new a;
echo "echo1: After Instantiation :<br/>";
xdebug_debug_zval('t1');echo "<br/><br/>";
$t2 = $t1;
echo 'echo2: After ...
17
votes
2
answers
489
views
What is exactly happening when instantiating with 'new'?
Let's consider the following code:
class a {
public $var1;
function disp(){
echo $this->var1;
}
}
$obj1 = new a;
echo '<br/>After instantiation into $obj1:&...
3
votes
3
answers
2k
views
How does array_keys do the search for value?
How does PHP array_keys do the search for value?
Example:
$array2 = array("xyz", "xyz", "abc", "abc", "xyz", "xyz", "text", "abc", "text");
print_r(array_keys($array2,"abc"));
Since they are key,...
1
vote
1
answer
130
views
When does a 'symbol' / 'variable name' get created in PHP?
This is my setting:
display_startup_errors = on
display_errors = On
error_reporting = E_ALL | E_STRICT
//code1:
$a = "abcd";
xdebug_debug_zval('a');
The above line of code would create a zval ...
14
votes
2
answers
2k
views
how does PHP opcode relate to the actually executed binary code?
test.php as plain text:
<?php
$x = "a";
echo $x;
test.php as opcode:
debian:~ php -d vld.active=1 -d vld.execute=0 -f test.php
Finding entry points
Branch analysis from position: 0
Return found
...
11
votes
2
answers
3k
views
Writing PHP opcode and have it executed. How to do?
How can I write PHP opcode, save it in a file and make the Zend Engine execute it? Any method or hack is welcome, as long as it does the trick.
0
votes
1
answer
78
views
Extending the Zend Engine on a KDE platform, is gVIM the right choice?
I am trying to introduce few nifty cool concepts to the Zend Engine in a KDE environment. It's kinda "deep core" thing and requires lots and lots of veteran C coding and hacking around a moderately ...
11
votes
1
answer
149
views
zend custom module
I am trying to build my own zend module (.so)
We have multiple functionality that can be done in our own module which will improve our performance on a high traffic website (50k+ visits a day).
...
2
votes
1
answer
158
views
Wrapping a custom php extension
I'm trying to wrap a custom php extension from a C library, now I have an Initializer function which initiate a specific custom connection and seems to be expensive one and i should not run it each ...
2
votes
2
answers
986
views
Add entry to $_SERVER in extension
I need to add an entry to the superglobal $_SERVER-array within a PHP extension. I am quite sure that php_register_variable() will do the job, paasing key and value as arguments; but I have no idea ...
1
vote
1
answer
427
views
Zend extension, get arguments of echo?
We have made a Zend extension which we want to write the addresses of the zval's echo is supposed to write out, but we cannot figure how to receive them because we have noticed that there is ...
0
votes
1
answer
495
views
php extension method not returned why?
Here is the php_ex.cc . When I compile my .so library the retur() method is not working. WHY? I have no errors, but It should print "test" and it doesn;t . need some help.THX
[php_ex.cc]
#include "...
1
vote
1
answer
2k
views
php extension how to return a string from a method?
I have in [example.cc] a method :
std::string Car::accelerate (std::string n)
{
cout<<n<<endl;
return n;
}
I would like to call this method from a php extension
I wrote this in my [...
2
votes
2
answers
736
views
how to access a variable from a class using php extension?
I am working in c++ under ubuntu. I have the following example:
[car.h]
#ifndef VEHICLES_CAR_H
#define VEHICLES_CAR_H
// A very simple car class
class Car {
public:
Car();
void shift(int ...
1
vote
1
answer
148
views
Array as class member and refcounting
There is something that confuses me. Let there be a class member
Foo::$bar, which has to be initialized as an empty array in the
constructor. If I do that (via zend_update_property), its refcount is ...
9
votes
0
answers
1k
views
PHP Zend Engine Extension static method call [closed]
I am writing a PHP extension. From the C code I try to invoke a static method in PHP code.
The PHP-method looks like this:
<?php
class Model {
static method GetModelById($id) { ... }
}
?>
...
8
votes
3
answers
834
views
puzzling php parser error
Ok maybe not so puzzling, but here it is.
I was messing around and noticed this, typing just <?php in a file, just that, no space after that, nothing else just the tag, throws a parse error.
...
52
votes
2
answers
3k
views
Parentheses altering semantics of function call result
It was noted in another question that wrapping the result of a PHP function call in parentheses can somehow convert the result into a fully-fledged expression, such that the following works:
<?php
...
1
vote
2
answers
261
views
PHP array syntax/operator?
When writing the syntax for an associative array in PHP we do the following
$a = array('foo' => 'bar');
I am curious of the relationship of the => syntax, or possibly operator. Does this relate ...
1
vote
1
answer
177
views
How does PHP implements its all fit container `array`?
If it were c++,this can be achieved by template,but as we know PHP is written in c,how's this kind of data struct implemented without template?
12
votes
1
answer
4k
views
How does PHP assign and free memory for variables?
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?...
5
votes
1
answer
630
views
How does the PHP MongoDB Driver's Cursor buffer a result set?
When queries are made to mongodb, how does it's cursor deal with the result set in memory? Does the cursor retrieve all documents which match the query, at once? or does it retrieve 1 document at a ...
10
votes
1
answer
6k
views
PHP's MySQL Cursor implementations and how they manage memory
How do the different MySQL Cursors within PHP manage memory? What I mean is, when I make a MySQL query that retrieves a large result set, and get the MySQL resource back, how much of the data that ...
22
votes
2
answers
1k
views
Interchanging data with zend (multidimensional arrays)
I'm embeding PHP in my app (writen in Delphi 2010), using PHP4Delphi component to interface with php5ts.dll.
I guess my program acts as extension for the PHP (sapi module?) as it registers some ...
2
votes
1
answer
625
views
Make getimagesize() referenced cached values
I am tweaking a zen-cart website to be more cpu efficient. After profiling it, I see that the getimagesize function is accounting for nearly 50% of page load time. The images are locally stored. One ...
4
votes
3
answers
536
views
PHP's static member and instance member seems no different. Why PHP does so(Without warning)?
<?php
class A {
public function instanceFunc() {
echo "instance";
}
public static function staticFunc() {
echo "static";
}
}
A::instanceFunc(); // instance
$a = new A();
$a->...
4
votes
3
answers
2k
views
How are PHP's built-in functions implemented internally?
are these functions written the same way as user functions? I mean with PHP code and with regular expressions and stuff like that?
For example:
filter_var($email, FILTER_VALIDATE_EMAIL);
vs.
http:/...
16
votes
1
answer
16k
views
how to write PHP module in C
how can i write my own module in C ?
is it possible ?
1
vote
1
answer
1k
views
Linking a php module with a .so library on linux
I am working on a PHP module and I am having trouble linking with shared libraries under Linux.
What is the command I need to put in my config.m4 to link against a .so?
If I have my .so file under /...
1
vote
1
answer
788
views
try to embed my C code in PHP script
I am learning how to use SWIG, and I am writing a php wrapper for a C library. The extension successfully compiles, but when I try to call the function I get this error:
php: symbol lookup error: /...
8
votes
3
answers
4k
views
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 ...
1
vote
2
answers
327
views
How can I make/patch php source (c code) to read an array from php.ini?
I'm experienced with php but I'm a novice to the php source and php extensions. I want to extend php so that it randomly chooses an upload_tmp_dir from an array, rather than one fixed dir.
It doesn't ...
28
votes
5
answers
7k
views
Detecting whether a PHP variable is a reference / referenced
Is there a way in PHP to determine whether a given variable is a reference to another variable and / or referenced by another variable? I appreciate that it might not be possible to separate ...
1
vote
2
answers
270
views
Php extension problems
I get a tricky problem when i am trying to create a php extension with c, with an array returned.
I do as some tutorials said, but i need to return an array.
array_init(return_array) in all examples ...
3
votes
1
answer
833
views
PHP Zend Engine Extension and static methods
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:
...
1
vote
1
answer
300
views
How do I create an empty op_array?
In my PHP extension, how can I create an op_array with no opcodes in it?
32
votes
4
answers
7k
views
Where can I learn about PHP internals? [closed]
What are good resources to start learning the internals of PHP and the Zend Engine?
0
votes
1
answer
639
views
Can't find Zend directory in EasyPHP folder
I'm about reading a tutorial about creating php extensions in C. I'm using Visual Studio 2008 and EasyPHP whose directory includes /ext folder (PHP extensions directory)
this is the tutorial : http://...
2
votes
2
answers
559
views
Which PHP function uses such hash algorithm?
1. static inline ulong zend_inline_hash_func(char *arKey, uint nKeyLength)
2. {
3. register ulong hash = 5381;
4.
5. /* variant with the hash unrolled eight times */
6. ...
0
votes
4
answers
208
views
Anyone familiar with PHP source code?
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &r1, &n, &r2, &m)
What's "ss" for here?
5
votes
4
answers
765
views
How to understand the 3 lines of c code?
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) {
return;
}
Especially what's ZEND_NUM_ARGS() TSRMLS_CC doing?
3
votes
3
answers
2k
views
PHP String Length Without strlen()
Just browsing over the latest release of the PHP coding standards, and something caught my eye:
http://svn.php.net/viewvc/php/php-src/trunk/CODING_STANDARDS?revision=296679&view=markup
Coding ...
6
votes
8
answers
3k
views
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)
8
votes
6
answers
4k
views
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 ...
43
votes
6
answers
7k
views
Why don't PHP properties allow functions?
I'm pretty new to PHP, but I've been programming in similar languages for years. I was flummoxed by the following:
class Foo {
public $path = array(
realpath(".")
);
}
It produced a ...