your Zend_Config - Object is holding the String "PDO::ATTR_TIMEOUT"
instead of the integer representation of this constant (which is 2).
I am using similar stuff and my corresponding part of the config looks
like this:
["driver_options"] => object(Zend_Config)#134 (7) {
["_allowModifications:protected"] => bool(true)
["_index:protected"] => int(0)
["_count:protected"] => int(2)
["_data:protected"] => array(2) {
[1002] => string(16) "SET NAMES "utf8""
[3] => int(2)
}
(where 1002 means "PDO::MYSQL_ATTR_INIT_COMMAND" and 3 means
"PDO::ATTR_ERRMODE")
Regards,
Georg
block.jon schrieb:
> Hi Ralph! Thanks so much for pitching in to help me. I just can't seem to get
> this to work. Here's what I want:
>
> I'm testing what would happen if my app tried to connect to a machine that
> isn't responding. In order to simulate this, I'm giving Zend_Db an IP
> address to connect to that doesn't exist... "5.4.3.2". I did a "print_r()"
> on my config object so you can see how I'm doing it. As you can see, i set
> the PDO::ATTR_TIMEOUT to "2", and my expectation is that after 2 seconds, it
> will throw a timeout exception. However, it hangs for 30 seconds so it
> doesn't seem like my ATTR_TIMEOUT is getting used.
>
> Zend_Config Object
> (
> [_allowModifications:protected] =>
> [_index:protected] => 0
> [_count:protected] => 2
> [_data:protected] => Array
> (
> [adapter] => PDO_MYSQL
> [params] => Zend_Config Object
> (
> [_allowModifications:protected] =>
> [_index:protected] => 0
> [_count:protected] => 6
> [_data:protected] => Array
> (
> [username] => demo
> [password] => test
> [port] => 3389
> [dbname] => guestbook
> [host] => 5.4.3.2
> [driver_options] => Zend_Config Object
> (
> [_allowModifications:protected] =>
> [_index:protected] => 0
> [_count:protected] => 1
> [_data:protected] => Array
> (
> [PDO::ATTR_TIMEOUT] => 2
> )
>
> [_loadedSection:protected] =>
> [_extends:protected] => Array
> (
> )
>
> [_loadFileErrorStr:protected] =>
> )
>
> )
>
> [_loadedSection:protected] =>
> [_extends:protected] => Array
> (
> )
>
> [_loadFileErrorStr:protected] =>
> )
>
> )
>
> [_loadedSection:protected] =>
> [_extends:protected] => Array
> (
> )
>
> [_loadFileErrorStr:protected] =>
> )
>
>
>
>
> Ralph Schindler-2 wrote:
>> Actually, the connection is not made until the first request.
>> Zend_Db::factory() produces a Zend_Db_Adapter for you to work with but the
>> Zend_Db_Adapter will only create a connection when it needs to (first
>> request, this is known as "lazy-loading").
>>
>> So, if you want to manage "connection" timeouts, (lets assume PDO for
>> this),
>> this is something you'd have to pass into the "driver_options" section of
>> the config. You would be looking for a attribute like "ATTR_TIMEOUT" or
>> something to that effect if I recall correctly.
>>
>> You'd want to consult the PDO pages of php.net to ensure this, and if you
>> are using a different adapter, the manual pages for that adapter, as these
>> are driver specific options.
>>
>> Also, to effectively enforce this, you'd have to call
>>
>> $dbAdapter = Zend_Db::factor(..);
>> $dbAdapter->getConnection();
>>
>> To start the connection after adapter creation.
>>
>> -ralph
>>
>> On 1/5/09 5:01 PM, "block.jon" <jblock@hotornot.com> wrote:
>>
>>> How do I set my connection timeout when I create an adapter?
>>>
>>> Here's what I've got now....
>>>
>>> $adapterToAdd = Zend_Db::factory($zend_db_config);
>>>
>>> I want it to fail if it doesn't get a connection within 15 seconds. The
>>> default seems to be 30 seconds.
>>>
>>> Thank you!!
>>> Jon
>> --
>> Ralph Schindler
>> Software Engineer | ralph.schindler@zend.com
>> Zend Framework | http://framework.zend.com/
>>
>>
>>
>>
>
没有评论:
发表评论