PVi1 Posted May 9, 2009 Share Posted May 9, 2009 Hello all, I have created my custom php extension, which is running transparently on every user request(looking for compiled script name and connect to DB for getting some info about script owner). The problem is that I am not able to create persistent connection which will survive between requests. If I send request one after another,it works. But when there is a delay between request cca 5secs or more, connection is not found and a new one is created. I have no PHP_FUNCTION in my extension. I am only working by overloading zend_compile_file functions. So i don't receive any parameters/arguments from userspace. Here is snippet of function where I am checking for connection.I have followed tutorial for creating persistent resources, but every tutorial is working with values received from userspace side and using zend_parse_parameters for creating resources: http://pastebin.com/m5f1100e9 Yes, I know it is terrible piece of code, but I'm working on it for 24hours withat any positive result. Here is example of tutorial: http://devzone.zend.com/article/1024-Extension-Writing-Part-III-Resources#Heading8 When i have followed tutorial, my extension failed due to wrong initialized zval "identifier" resource.I am not able to create zval resource from string. I was getting error "supplied argument is not mysql connecion handler resource", because of zval identifier is not is_resource. Enviremoent> Ubuntu 9.04, php 5.2.6, mysql 5.0.75 Could somebody write me how to create persistent database connection handler? Thanks in advance, Peter. Link to comment https://forums.phpfreaks.com/topic/157484-solved-persistent-mysql-connection-initialized-from-inside-of-my-extension-not-working/ Share on other sites More sharing options...
PVi1 Posted May 9, 2009 Author Share Posted May 9, 2009 OK, problem solved. I have forgotten that my apache is running multiprocess, so more than one connection to db have to be established. After analyzing zend_list.c I have found workaround to zval is_resource,too. zval *return_value; The solution was add "return_value" like passed_id(The resource value to look for as zval**) ZEND_REGISTER_RESOURCE(return_value, con_handler->ptr, le_test_descriptor_persist_acl); ZEND_FETCH_RESOURCE(aktual, mysql_conn_rbac*, &return_value, -1, "MySQL GACL connection handler",le_test_descriptor_persist_acl); Best regards, Peter. Link to comment https://forums.phpfreaks.com/topic/157484-solved-persistent-mysql-connection-initialized-from-inside-of-my-extension-not-working/#findComment-830477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.