Re: [fw-general] Incredible memory usage on public server, normal on dev server

2009-11-10 Thread Luke Richards

Done

http://framework.zend.com/issues/browse/ZF-8278

Matthew Weier O'Phinney wrote:

-- Luke Richards  wrote
(on Tuesday, 10 November 2009, 02:28 PM +):
  

We use the Zend_Mail classes where I work and we're sending a lot of emails. It
was a while ago but I think we had the same problem running out of memory. We
tracked the problem down to the ZF SMTP transport. If you are using that try
overriding it with the following code. We found the problem to be a log being
kept on the abstract protocol class. Each time the protected send method is
called is attaches the request to the end of the log.



Could you post an issue in the tracker indicating this, as well as your
fix? It's probably something we should resolve.

  

class Yourlibrary_Mail_Transport_Smtp extends Zend_Mail_Transport_Smtp
{
/**
 * Send a mail using this transport
 *
 * @param  Zend_Mail $mail
 * @access public
 * @return void
 * @throws Zend_Mail_Transport_Exception if mail is empty
 */
public function send(Zend_Mail $mail)
{
$connection = $this->getConnection();
if ($connection instanceof Zend_Mail_Protocol_Smtp) {
$connection->resetLog();
}
return parent::send($mail);
    }
}



  


--
Luke Richards

Emailcenter UK Limited
Kingthorn Park
Bradden Road
Greens Norton
Towcester
Northamptonshire
NN12 8BS

e: luke.richa...@emailcenteruk.com
t: 01327 350921
f: 01327 359502
www.emailcenteruk.com

UK Leaders in permission email marketing solutions and services
Privileged/Confidential information may be contained in this message. If you 
are not the addressee indicated in this message (or responsible for delivery of 
the message to such person), you may not copy or deliver this message to 
anyone. In such cases, you should destroy this message, and please notify us 
immediately.

Please advise immediately if you or your employer does not consent to Internet 
e-mail for messages of this kind. Opinions, conclusions and other information 
expressed in this message are those of the author and not necessarily endorsed 
by Emailcenter UK Limited unless indicated by an authorised representative of 
the company independent of this message. If you need to contact Emailcenter 
please call ++44(0) 1327 350921.

Emailcenter UK Limited is registered in the UK. Reg No.04254916 



Re: [fw-general] Incredible memory usage on public server, normal on dev server

2009-11-10 Thread Luke Richards

Hi,

We use the Zend_Mail classes where I work and we're sending a lot of 
emails. It was a while ago but I think we had the same problem running 
out of memory. We tracked the problem down to the ZF SMTP transport. If 
you are using that try overriding it with the following code. We found 
the problem to be a log being kept on the abstract protocol class. Each 
time the protected send method is called is attaches the request to the 
end of the log.


class Yourlibrary_Mail_Transport_Smtp extends Zend_Mail_Transport_Smtp
{
   /**
* Send a mail using this transport
*
* @param  Zend_Mail $mail
* @access public
* @return void
* @throws Zend_Mail_Transport_Exception if mail is empty
*/
   public function send(Zend_Mail $mail)
   {
   $connection = $this->getConnection();
   if ($connection instanceof Zend_Mail_Protocol_Smtp) {
   $connection->resetLog();
   }
   return parent::send($mail);
   }
}

Hope that helps someone.

drm wrote:

Did you ever find out what was going on?



Re: [fw-general] Zend_XmlRpc_Server

2008-10-17 Thread Luke Richards

Hi Matthias,

I think the reason get_contact isn't working is because the the Zend 
Server components rely on docblocks to describe the function/method 
parameters. I've tried the following and it seems to work.


function version() {
   return 1;
}

/**
*
* @param int $id
* @return int
*/
function get_contact($id) {
   return 42;
}

$request = new Zend_XmlRpc_Request('get_contact', array('id' => 12));

$server = new Zend_XmlRpc_Server();
$server->addFunction('get_contact');
$server->addFunction('version');
echo $server->handle($request);

Hope that helps.

Luke R

Matthias Coy wrote:

Hi there,

so this is basically my code:

addFunction('get_contact');
$server->addFunction('version');
echo $server->handle();


I use xmlrpc (http://xmlrpc-c.sourceforge.net/) to test the server, 
basically it's


xmlrpc http://localhost/zend_xmlrpc.php version

which returns:

Result:
Integer: 1

so far so good. But I'm unable to call the get_contact function, 
because  it's always saying:


Error: RPC failed at server.  Calling parameters do not match 
signature (623)


So, first thought was: maybe a broken client. So I tried the 
Zend_XmlRpc_Client:


http://localhost/zend_xmlrpc.php');
echo $client->call('get_contact', array("sth"));


didn't work either. So what am I doing wrong?

I'm using Zend Framework Revision 11997 and PHP 5.2.6.

Regards
Matthias



Re: [fw-general] Catching catched exceptions

2008-10-08 Thread Luke Richards

Hi

try {
   $result = $db->query(...);
   $db->update(...);
   // other code
} catch(Exception $e) {
   // do something here
   throw $e
}

The important bit is that you are re-throwing the exception that you've 
caught. Alternatively you could throw a new exception but you'll loose 
the context data stored in the exception such as where the original 
error occurred. The error controller should by default be setup to catch 
the exception.


Hope that helps.

Luke

Mauricio Cuenca wrote:

Hello Marcelo,

It's basically something like this:

try {
$result = $dbconn->query("SELECT * FROM TABLE");
} catch (Exception $e) {
echo "Something is wrong...";
exit();
}

I could modify the catch part and do some redirection or something similar,
but the code has many SQL calls like this. I don't want to change each one
manually.



Marcello Duarte wrote:
  

What code is in your catch statement?


Mauricio Cuenca wrote:


Hello,

I have an application that started small and now its big. The problem is
that each database transaction has a try/catch statement.

Now I want to capture all those exceptions and send them to the error
controller to display friendly error messages to users in the production
environment.

Is there a way to force the Error Controller to catch this already
catched exceptions without modifying each sql try/catch block in the
code?

Thanks!

  



  


Re: [fw-general] Zend_Db_Select question

2008-08-21 Thread Luke Richards

Try:

$select->from(
   'tablename',
   array(
   '*',
   'product' => new Zend_Db_Expr($db->quote('aaa'))
   )
   );

Luke R

Nikolay Alexeev wrote:

Though, it is clear, why id didn't work:


Zend Framework wrote:
  

class Zend_Db_Expr
{

protected $_expression;
public function __construct($expression)
{
$this->_expression = (string) $expression;
}
public function __toString()
{
return $this->_expression;
}
}





So, i think, i need any other method. If it is possible. 
  


Re: [fw-general] [blog] creating simple ZF website with user registration

2008-05-20 Thread Luke Richards

Happy to help.

The reason I included the plug-in was so your bootstrap could be a bit 
cleaner and easier to read, always a good thing(tm). Also it centralises 
setting up the encoding for different objects. So for example if you 
wanted to set the encoding for the database as well. Another example 
might be that you want to examine the response object and add the 
encoding for certain content types before the response is sent (like 
text/*). Additionally you could detect the Accept-Encoding header 
provided by the client in the request object. All could be done from the 
one plug-in.


Luke

Viper X wrote:

Thanks Luke, Matthew. Of course you are right. So when we have in the layout
template 




the 


$response->setHeader('Content-Type', 'text/html; charset=UTF-8', true);

adds nothing more, but prevents us from sending other content if we need
this later. So I'll drop it. It was a bit of reinsurance from my side, not
well thought out.

But for setting the encoding to the View object - I think there is no need
of special plugin for this, when we can just make it with 3 lines in the
bootstrap:

$view = new Zend_View(array('encoding'=>'UTF-8'));
$viewRendered = new Zend_Controller_Action_Helper_ViewRenderer($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRendered);


Regards,
Andrei



Luke Richards wrote:
  

Hi Viper,

I looked through 'Part 2' quickly. Something that did catch my eye was 
the part where you return the response from the front controller in your 
bootstrap and set the content type header to be text/html. I assume 
you've done this to set the UTF-8 encoding? What happens if you want to 
return JSON, XML or file downloads from part of your application as a 
response? The response object force ably overwrites any headers set to 
text/html.


Based on the following thread, it seems setting the encoding in the 
header isn't necessary as long as it's in the HTML.

http://www.nabble.com/Best-place-to-specify-encoding-tf4621717s16154.html#a13198947

As for the view perhaps you could use a plug-in like so:
class My_Plugin_SetEncoding extends Zend_Controller_Plugin_Abstract {
   
protected $_encoding;
   
public function __construct($encoding = 'utf-8')

{
$this->_encoding = $encoding;
}
   
public function preDispatch($request)

{

Zend_Controller_Action_HelperBroker::getHelper('ViewRenderer')->view->encoding 
= $this->_encoding;

}
}

and then in your bootstrap

Zend_Layout::startMvc(
array <http://www.php.net/array>(
'layoutPath' => $siteRootDir . '/application/layouts',
'layout' => 'main'
)
);

Zend_Controller_Front::getInstance()
  ->throwExceptions(true)
  ->registerPlugin(new My_Plugin_SetEncoding('utf-8'))
  ->addModuleDirectory($siteRootDir . '/application/modules')
  ->dispatch();

Just a suggestion (I've not actually tried the code so I'm not sure if 
it works, specifically ..._HelperBroker::getHelper part as the method 
isn't defined as static?? Although the method does seem to be able to 
operate as a static?? Can anyone explain?).


Luke

Viper X wrote:


Hi all there.

I'm writing simple web application to be used from me as "kick-start"
when
starting new application, which needs user registration and
authentication. 


I think it can be interesting for someone to see my approach to the
problem
and eventually to use some of my code for his own purpose :) So i decided
to
put the code along with some descriptions to a blog series here:

http://zfsite.andreinikolov.com http://zfsite.andreinikolov.com 


Now there is only the first part - setting up the MVC, later today I hope
I
will manage to write the next part - putting the session management in
the
database. 

I'll appriciate any comments on it. 

  
  



  


Re: [fw-general] [blog] creating simple ZF website with user registration

2008-05-20 Thread Luke Richards

Hi Viper,

I looked through 'Part 2' quickly. Something that did catch my eye was 
the part where you return the response from the front controller in your 
bootstrap and set the content type header to be text/html. I assume 
you've done this to set the UTF-8 encoding? What happens if you want to 
return JSON, XML or file downloads from part of your application as a 
response? The response object force ably overwrites any headers set to 
text/html.


Based on the following thread, it seems setting the encoding in the 
header isn't necessary as long as it's in the HTML.

http://www.nabble.com/Best-place-to-specify-encoding-tf4621717s16154.html#a13198947

As for the view perhaps you could use a plug-in like so:
class My_Plugin_SetEncoding extends Zend_Controller_Plugin_Abstract {
  
   protected $_encoding;
  
   public function __construct($encoding = 'utf-8')

   {
   $this->_encoding = $encoding;
   }
  
   public function preDispatch($request)

   {
   
Zend_Controller_Action_HelperBroker::getHelper('ViewRenderer')->view->encoding 
= $this->_encoding;

   }
}

and then in your bootstrap

Zend_Layout::startMvc(
   array (
   'layoutPath' => $siteRootDir . '/application/layouts',
   'layout' => 'main'
   )
);

Zend_Controller_Front::getInstance()
 ->throwExceptions(true)
 ->registerPlugin(new My_Plugin_SetEncoding('utf-8'))
 ->addModuleDirectory($siteRootDir . '/application/modules')
 ->dispatch();

Just a suggestion (I've not actually tried the code so I'm not sure if 
it works, specifically ..._HelperBroker::getHelper part as the method 
isn't defined as static?? Although the method does seem to be able to 
operate as a static?? Can anyone explain?).


Luke

Viper X wrote:

Hi all there.

I'm writing simple web application to be used from me as "kick-start" when
starting new application, which needs user registration and authentication. 


I think it can be interesting for someone to see my approach to the problem
and eventually to use some of my code for his own purpose :) So i decided to
put the code along with some descriptions to a blog series here:

http://zfsite.andreinikolov.com http://zfsite.andreinikolov.com 


Now there is only the first part - setting up the MVC, later today I hope I
will manage to write the next part - putting the session management in the
database. 

I'll appriciate any comments on it. 

  


Re: [fw-general] Zend_Db_Table - A class for every table? Overhead?

2008-05-20 Thread Luke Richards

Hi Philip,

One suggestion might be to use the Zend_Cache with Zend_Db_Table. Using 
the cache means you won't get the describe request overhead except for 
the first time populating the cache (per table).


http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.metadata.caching

Hope that helps a little.

Luke

Philip G wrote:
On Mon, May 19, 2008 at 4:02 PM, Bradley Holt 
<[EMAIL PROTECTED] > wrote:


Philip,

On Mon, May 19, 2008 at 4:54 PM, Philip G <[EMAIL PROTECTED]
> wrote:


I'm at a bit of an impasse here.

I'm trying to understand the reason for having a Zend_Db_Table
object for every table in the database while balancing the
class creation overhead. In PHP, creating a class (especially
a Zend_Db_Table class) has a fair bit of overhead. It's not
something that's small either. A quick creation of 7-8 objects
can easily slow the application down by 3-4 seconds. 



Do you have some data to back that up? I've never heard of object
creation being anywhere close to that slow in PHP. I would think
the time to create an object would be negligible compared to the
overhead of database access itself.
 



Sure. I'll try to get a little test together. I happen to have 
experienced first hand looping over ~8-10 "survey answers" where 
initially I created a new table object for each one.


My program was up to 5-6 seconds to complete. I traced it down to one 
section where I was looping over all my survey answers and inserting 
them into the table (one row per answer). Initially, I created a new 
class for each one. My thought was "a new row, a new class" -- I did 
that, but it slowed down that section by 3 seconds. So I changed my 
wrapper class to use a static variable for the table and did an 
insert() against that. Dropped it down to under a second execution for 
that one section.


theories as to the cause:
 - Our DB is Oracle, on a remote host. We have remote connection lag.
 - Every time you create a new DB Table object, Zend_Db pulls a 
describe. That describe adds noticeable lag when looping over 8 
objects within seconds.
 - Creating a new class isn't obtimal, but does show natural possible 
lag issues.


I was creating a new table object for every row getting inserted; 
which was probably a bad idea. However, it does show an example on how 
creating table objects can slow down code.


(on and yes, each object was using the same static db connector)

Additionally, object creation overhead is going to be insignificant
compared to DB access; I've created scripts that create many thousands
of objects in under a second.


I'm curious on the benchmarks on creating classes. I'm often in 
battles with a fellow co-worker about class creation. lol
He's a speed extremist; and I mean extremist. He's all about pulling 
even the most minute of milliseconds out for speed (eg: he advocates 
if/else instead of ternary). It's hard to get him on board when PHP 
objects have an inherited overhead. :(
This above example is an extreme case, but definitely shows the 
inherent lag within PHP class creation. It's a bit hard to speak for 
PHP classes when we do see this lag issues. He's very, very much 
against constant class creation -- hard to argue without real ammo 
against it.



wow that seems slow, try looking for any
sleep(rand(3,4));

only j/k lol ;-)



Ha. I laughed. ;-)


--
Philip
[EMAIL PROTECTED] 
http://www.gpcentre.net/ 


Re: [fw-general] Zend_Mail Zend_Mail_Transport_Exception

2008-05-06 Thread Luke Richards

Hi,

Based on the code included, you are not specifying the transport to use. 
This means that Zend_Mail is using the default which is Sendmail. To 
change the default behaviour, try this:


|http://framework.zend.com/manual/en/zend.mail.sending.html|

|
require_once 'Zend/Mail/Transport/Smtp.php';
$tr = new Zend_Mail_Transport_Smtp('mail.example.com');
Zend_Mail::setDefaultTransport($tr);
|


Hope that helps.

Luke

Jerry McG wrote:

Hi All,

I am attempting to use Zend_Mail via the default
Zend_Mail_Transport_Sendmail transport on my local Windows machine. But for
some reason I am getting error "Fatal error: Uncaught exception
'Zend_Mail_Transport_Exception' with message 'Unable to send mail' in
D:\Path\library\Zend\Mail\Transport\Sendmail.php."

Should I change any configuration info in php.ini file before I use
Zend_Mail? At present my php.ini has the below:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = [EMAIL PROTECTED]

I am attempting the following code:


require_once 'Zend/Mail.php';
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('[EMAIL PROTECTED]', 'Some Sender');
$mail->addTo('[EMAIL PROTECTED]', 'Some Recipient');
$mail->setSubject('TestSubject');
$mail->send();

Thanks!

Jerry