C PHP Extension object persistance
Asked Answered
H

1

11

I've developed a PHP5 client extension for a server application i wrote, and so far it's working quite well, but it doesn't support persistent connections yet. Since this is something i want to implement before releasing the first stable version, i was searching for documentation about persistance and found the persistent allocation routines ( pemalloc, pecalloc, etc ). What i can't understand is how to retrieve a persistently allocated object upon new requests, i mean, let's say that the persistent id of a connection is:

<hostname>:<port>:<timeout>

How do i save ( or check if it was already created ) the connection object ( which is a C structure, not a zval or anything strictly PHP related ) ? How can i retrieve it later given its id ?

PS: I know about PHP persistent streams ( i've studied the pfsockopen C sources ), but i use a C client library so i can't access the socket directly or modify the C client library to use php streams instead of plain sockets.

Thanks.

Harebell answered 5/7, 2013 at 8:26 Comment(6)
Persistent connections are considered at least problematic for a stateless web server design. Why do you want to implement this? I would try to create a connection pool, if possible, and try to reinitialize and reuse existing onesValeriavalerian
yep this is a great idea too, but i'd need persistance anyway, so the question remains the same :)Harebell
Interesting problem, anyway. :) I fear I cannot help you more with this as its seems that you know already much more about this as me. But I've added a fav and I'm curious how the answer will look like.Valeriavalerian
well you gave me a good idea! once i'll figure out how to set/get persistant objects i will think about it as a possible optimization to the standard single persistent connection ... so, thanks! ^^Harebell
Why not steal the concept of session or a descriptor? Launch off your persistent connection as a back-end process, and pass your opaque descriptor around to keep track of the persistent connection?Cheater
I'd like to find ( since i know it can be done ) a way without using other processes.Harebell
H
4

Found the solution, it seems there's a "persistent_list" hash object, so I'm able to do:

zend_hash_find(&EG(persistent_list), ...

To find persistent data ( allocd with pemalloc obviously ), and

zend_hash_update(&EG(persistent_list), ...

To save new instances.

( Found this in the PostgreSQL php extension source code. )

http://devzone.zend.com/446/extension-writing-part-iii-resources/#Heading8

Anyone interested in my approach, it's here https://github.com/evilsocket/phpgibson

Harebell answered 5/7, 2013 at 15:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.