Browsing the archives for the php 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

Old code.

Code, php

I love coming across old code *cough* garbage *cough*

The purpose of this was to take a title, and create something url safe and in the fashion a client was wanting. The first function was old code, so don’t blame me.

function cleanUrl($url)
{
  $find =        array('/--/', '/ - /','/ /', '/!/', '/"/', "/'/", '/--/');
  $replace =    array('-', '-', '-', '', '', '', '-');

  $result = strtr($url, "`~@#$%^&*()_=+|[]{};:,./<>?", "---------------------------");

  return strtolower(preg_replace($find, $replace, strip_tags(stripslashes(trim($result)))));
}

Isn’t it horrible?

I rewrote the function to…

function cleanUrl($url)
{
  $url = strtolower($url);

  $url = preg_replace("/[^a-z0-9\s+]/", '', $url);
  $url = preg_replace("/[\s]{1,}/", '-', $url);

  return $url;
}

That makes me happier.

1 Comment