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/
>
>
>
>
--
View this message in context: http://www.nabble.com/How-do-I-set-Zend_DB-connection-timeout--tp21301315p21318078.html
Sent from the Zend DB mailing list archive at Nabble.com.
没有评论:
发表评论