Browsing the archives for the Zend Framework category.

Zend Soap Client timeout

Zend Framework, php

I’m working with a web service that’s showing to be slow at times. The default timeout in PHP is 30 seconds currently, so waiting around for it to timeout kinda sucks.

I decided to set the timeout to 10 seconds, to my surprise the timeout code is completely commented out in the class.

However they do provide a setStreamContext(), so I set http to timeout after 10 seconds like so:

$context = stream_context_create(array('http' => array('timeout' => 10)));
$soapClient->setStreamContext($context);

When the service slowed down to 15 second wait times, it died out early like it should have. I’m catching the exception, which isn’t pretty. Wish I knew when it was timing out, so I could log that specific case.

No Comments

Zend Form Element Radio and Default value

Code, Zend Framework

I setup a Zend Form object and needed radio buttons, but also needed a default value. Took me a few minutes to find, but here’s an example of use.

/**
 * Setting some values for our radio buttons.
 */
$options = array(
    '1' => 'Option 1',
    '2' => 'Option 2',
    '3' => 'Option 3'
);

/**
 * The array('value' => 2) below sets our default value.
 */
$radio = new Zend_Form_Element_Radio('elementName', array('value' => '2'));
$radio->addMultiOptions($options);
$this->addElement($radio);
No Comments