Re: Static array & PHP CLI
| From: | Patrick ALLAERT | Date: | Mon, 25 Jun 2012 15:32:57 +0000 |
| Subject: | Re: Static array & PHP CLI | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-9542@lists.php.net to get a copy of this message | ||
Hi,
2012/6/25 William MARTIN <wysman@gmail.com>:
> Hi,
>
> I try to write a PHP extension to improve performance on some part of the
> PHP framework named Photon[1].
> Photon is a application server which run behind mongrel2 web server[2], so i
> use PHP CLI only, and never PHP CGI.
>
> One of the basic class of this framework is the configuration container,
> which contains a static associative array, and accesors. I have attached the
> class implemented in PHP.
>
> So, i have successively create :
> - a extension
> - a class into a namespace
> - add a zval into this class
>
> But i failed to create / use a PHP assoc array into this class. Most of the
> time is crash when the process is killed.
> I thinks i have some error near persistent or not memory allocation, because
> array_init call zend_hash_init with persitant = 0
> Does this concept exist in PHP CLI, or is for PHP CGI only ?
In CLI, you won't be able to use persistent data between two launches
of your PHP script. The "persistent" flag will tell the Zend memory
manager to not free the resource at the end of a request.
But when your script is done, it's not only the "request" that is
terminated but the whole PHP process and it's associated memory.
Maybe running your PHP script as a deamon is an alternative to handle
different "requests"?
That way you shouldn't write an extension just for the purpose of not
recreating an array on every requests.
> This is my first experience with a PHP extension.
> Does someone have good paper about writing PECL ?
> I have read this
>
> one http://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/
This isn't a paper, but a project that I created for the purpose of
helping people learning how to create a PECL extension:
https://github.com/patrickallaert/PHP_Extension_Workshop
You might be interested by clicking on one of the "compare" buttons
at: https://github.com/patrickallaert/PHP_Extension_Workshop/branches
Every branches correspond to a specific addition to an empty extension.
Creating an array isn't specifically mentioned, but again, I'm not
sure writing a PECL extension is the best/easiest way to go for you.
> If someone can share code about persistent array manipulation into a PECL, i
> will be very happy ;)
>
> Thanks,
> William MARTIN
>
> [1] http://www.photon-project.com/
> [2] http://www.mongrel2.org/
>
> --
> PECL development discussion Mailing List (http://pecl.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php