[fw-general] Zend_Table and dependentTables
Hi guys, I'm trying to use dependent tables in ZF and I ran into a problem I cannot solve for now. I have two tables. One, say, with a records of files and another with text to these files, defined by 'id' and 'language' which both form a primary key. Reference from the files-table is done by id and I want to get DependentRowset which only contains one row which I would like to define by the language column. Normally I would use WHERE clause in the select, but I am now trying to do this a ZF-way. The code is: // The table with file records class TablePublicImage extends Zend_Db_Table_Abstract { protected $_name = 'public'; protected $_primary = 'id'; protected $_dependentTables = array('TableComments'); } // The table with those language captions class TableComments extends Zend_Db_Table_Abstract { protected $_name = 'comments'; protected $_primary = Array('id', 'language'); protected $_dependentTables = array('TablePublicImage'); protected $_referenceMap= array( 'PublicImage' = array( 'columns' = array('id'), 'refTableClass' = 'TablePublicImage', 'refColumns'= array('comment'), 'onDelete' = self::CASCADE, )); } // Then I do something like this: $tpi = new TablePublicImage(); $tpi_data = $im-fetchAll(); foreach($tpi_data as $row) { $dep_rowset = $row-findTableCommentsByPublicImage(); // or $trans = $file-findDependentRowset('TableComments', 'PublicImage') } // and get a rowset which contains all records of captions from the TableComments with all languages. Is there a way to add some WHERE constraint to force the query to return just rows WHERE language='en' (for example)? Thanks a lot for replies, Jan Brucek
[fw-general] Re: Having problems using Zend Cache and Flickr
Anyone have an ideas on this? Im still stuck... On Wed, Nov 5, 2008 at 10:26 AM, Ian [EMAIL PROTECTED] wrote: Hi, I am having problems using Zend Cache and Service Flickr. The problem is that the array I get before caching is very different from the cache. Any ideas as to what im doing wrong? Here is my code: require_once('Zend/Loader.php'); Zend_Loader::registerAutoload(); Zend_Loader::loadClass('Zend_Cache'); Zend_Loader::loadClass('Zend_Service_Flickr'); Zend_Loader::loadClasS('Zend_Service_Flickr_ResultSet'); /* Setup cache options */ $frontendOptions = array( 'caching' = true, 'lifetime' = 600, // cache lifetime of 10 minutes 'automatic_serialization' = true ); $backendOptions = array( 'cache_db_complete_path' = '/cache/cache.sqlite' ); /* Init both vars */ $cache = Zend_Cache::factory('Core', 'Sqlite', $frontendOptions, $backendOptions); $flickr = new Zend_Service_Flickr(''); if(!$results = $cache-load('flickrcache')) { $results = $flickr-groupPoolGetPhotos(''); $cache-save($results, 'flickrcache'); } The print_r now shows this when retreived from cache: Zend_Service_Flickr_ResultSet Object ( [totalResultsAvailable] = 215 [totalResultsReturned] = 10 [firstResultPosition] = 1 [_results:protected] = DOMNodeList Object ( ) [_flickr:private] = Zend_Service_Flickr Object ( [apiKey] = [_restClient:protected] = Zend_Rest_Client Object ( [_data:protected] = Array ( ) [_uri:protected] = Zend_Uri_Http Object ( [_username:protected] = [_password:protected] = [_host:protected] = www.flickr.com [_port:protected] = 80 [_path:protected] = /services/rest/ [_query:protected] = [_fragment:protected] = [_regex:protected] = Array ( [alphanum] = [^\W_] [escaped] = (?:%[\da-fA-F]{2}) [mark] = [-_.!~*'()\[\]] [reserved] = [;\/?:@=+$,] [unreserved] = (?:[^\W_]|[-_.!~*'()\[\]]) [segment] = (?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@=+$,;])*) [path] = (?:\/(?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@=+$,;])*)?)+ [uric] = (?:[;\/?:@=+$,]|(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})) ) [_scheme:protected] = http ) ) ) [_currentIndex:private] = 0 ) And this when loaded originally: Zend_Service_Flickr_ResultSet Object ( [totalResultsAvailable] = 215 [totalResultsReturned] = 10 [firstResultPosition] = 1 [_results:protected] = DOMNodeList Object ( ) [_flickr:private] = Zend_Service_Flickr Object ( [apiKey] = [_restClient:protected] = Zend_Rest_Client Object ( [_data:protected] = Array ( ) [_uri:protected] = Zend_Uri_Http Object ( [_username:protected] = [_password:protected] = [_host:protected] = www.flickr.com [_port:protected] = 80 [_path:protected] = /services/rest/ [_query:protected] = [_fragment:protected] = [_regex:protected] = Array ( [alphanum] = [^\W_] [escaped] = (?:%[\da-fA-F]{2}) [mark] = [-_.!~*'()\[\]] [reserved] = [;\/?:@=+$,] [unreserved] = (?:[^\W_]|[-_.!~*'()\[\]]) [segment] = (?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@=+$,;])*) [path] = (?:\/(?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@=+$,;])*)?)+ [uric] = (?:[;\/?:@=+$,]|(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})) ) [_scheme:protected] = http ) ) )
[fw-general] Zend_Search_Lucene is very sloooooow
Hi, no that is not my opinion, that is the one sentence I heard most during the last IPC in Mainz when I talked to others about Zend_Search_Lucene. The widespread belief was that Zend_Search_Lucene is a very nice tool but it is damn slow with a larger index. I need to add that I did not find out if this is related to indexing or searching or both. So how are your experiences with Zend_Search_Lucene regarding performance? Is it really that slow when handling millions of datasets? Which process is slow, the indexing or the searching? Did anyone encounter performance issues with Zend_Search_Lucene and managed to solve it? If yes, how? What about best practices regarding performance. I just built an application yet that only has ~1.000 datasets and I did not notice any issues yet. But maybe someone worked on a much bigger index and can provide us with his or her experiences? Thanks and best regards, Ralf
Re: [fw-general] ZF application optimizations (and speedup)
-- Michael Depetrillo [EMAIL PROTECTED] wrote (on Thursday, 06 November 2008, 09:33 PM -0800): Does using autoload improve or reduce performance? I thought I saw an email by you where you stated in did. It improves performance, particularly when you strip out the require_once calls within Zend Framework (which you can do with a simple one-liner using find and sed). On Thu, Nov 6, 2008 at 6:28 PM, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: -- Sander van de Graaf [EMAIL PROTECTED] wrote (on Friday, 07 November 2008, 01:36 AM +0100): Hi all, Just wanted to point you to a blog post about some optimizations I found for a ZF project we're finishing up. It might be of interest to some of you: http://www.svdgraaf.nl/2008/11/07/optimizing-your-zf-web-application/ If you have any comments, please let me know. You have some interesting points about tuning the server and using CDNs that many people overlook when they consider optimizing their *site*, not just the applications. I also want to announce that I've been working on a performance guide appendix to the manual, and those of you following the subversion commits have likely noticed these commits. I have a lot of detail on ways you can reduce things like class loading overhead, how to optimize your views, etc. More tips will be added in the coming week as we approach the 1.7.0 release. -- Matthew Weier O'Phinney Software Architect | [EMAIL PROTECTED] Zend Framework | http://framework.zend.com/
Re: [fw-general] Zend_Db
Thanks so much!! On Nov 7, 2008, at 8:21 AM, Matthew Weier O'Phinney wrote: I sent my original reply to you, but I'm posting here for the archives. -- Edward Haber [EMAIL PROTECTED] wrote (on Friday, 07 November 2008, 07:09 AM -0500): Thanks for the help! It is much appreciated. I had a feeling I was doing something a bit fishy. I tried the code below and the method is returning an associative array instead of an array of Article objects. If I do change the setFetchMode globally in the bootstrap, it changes to stdClass. Is there a way I can get this method to return an array of Article objects? Aha -- that was the missing bit. By default, if you call fetchAll() on the _table_ object, it returns a Zend_Db_Table_Rowset object, which is simply an iterable object of Row objects. In the class definition you presented, this would mean that it would return a rowset populated by Article objects. The following achieves that: return $this-fetchAll($select); Alternately, if you really, really want to have it return an array instead of a rowset, do the following: $rowset = $this-fetchAll($select); $return = array(); foreach ($rowset as $row) { $return[] = $row; } return $return; Personally, I'd just use the Rowset -- it acts just like an array for all practical intents and purposes. On Nov 6, 2008, at 9:35 PM, Matthew Weier O'Phinney wrote: -- DorkFest [EMAIL PROTECTED] wrote (on Thursday, 06 November 2008, 05:58 PM -0800): This was posted in Dec 2007. I have the same question. Is there anyway using fetchAll and setFetchMode to set the explicit class name that's returned in the array? Or is this a design conflict? Here's basically the situation: class Articles extends Zend_Db_Table_Abstract { protected $_name = articles; protected $_rowClass = Article; public function fetchActive() { $db = Zend_Registry::get('db'); $db-setFetchMode(Zend_Db::FETCH_OBJ); $select = $db-select() -from($this-_name) -where('active = 1') -order('creation_date DESC'); // want to return array of articles objects here instead of stdClass return $db-fetchAll($select); } } class Article extends Zend_Db_Table_Row_Abstract { } Is this the wrong way to approach models? Or is there a better way to obtain the fetchAll array of Articles as a return value from the fetchActive() method. Umm... wow... that code is.. wow. First, when you have a Zend_Db_Table object, you already *have* the database adapter -- there's no need to grab it from the registry. Next, Zend_Db_Table also has its own select object now (since 1.5) that obviates the need to (a) pull it from the database adapter, and (b) specify the table name (it's automatically populated). Next, fetchAll() on the adapter already returns an array by default -- it has from the very beginning. You actually have to override this behavior to get a different return type by passing the fetchmode as the second parameter to the call. The reason you're getting anything different is because your code is calling: $db-setFetchMode(Zend_Db::FETCH_OBJ); which tells the adapter to return fetch results as objects. You're basically shooting yourself in the foot here. So, the following will do what you're trying to accomplish: public function fetchActive() { $select = $this-select() -where('active = 1') -order('creation_date DESC'); return $this-getAdapter()-fetchAll($select); } Renan Gonçalves wrote: Hello, How I can use fetchAll with fethMode = Object and using the class Article (for example) ? I can use fetchObject('Article') and will fetch on my class, but in fetchAll the default class is stdClass. The PDOStatement has the function: ( http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php) bool *setFetchMode* ( int $PDO::FETCH_CLASS , string $classname , array $ctorargs ) -- Matthew Weier O'Phinney Software Architect | [EMAIL PROTECTED] Zend Framework | http://framework.zend.com/
Re: [fw-general] Zend_Db
Thanks for the help! It is much appreciated. I had a feeling I was doing something a bit fishy. I tried the code below and the method is returning an associative array instead of an array of Article objects. If I do change the setFetchMode globally in the bootstrap, it changes to stdClass. Is there a way I can get this method to return an array of Article objects? Eddie On Nov 6, 2008, at 9:35 PM, Matthew Weier O'Phinney wrote: -- DorkFest [EMAIL PROTECTED] wrote (on Thursday, 06 November 2008, 05:58 PM -0800): This was posted in Dec 2007. I have the same question. Is there anyway using fetchAll and setFetchMode to set the explicit class name that's returned in the array? Or is this a design conflict? Here's basically the situation: class Articles extends Zend_Db_Table_Abstract { protected $_name = articles; protected $_rowClass = Article; public function fetchActive() { $db = Zend_Registry::get('db'); $db-setFetchMode(Zend_Db::FETCH_OBJ); $select = $db-select() -from($this-_name) -where('active = 1') -order('creation_date DESC'); // want to return array of articles objects here instead of stdClass return $db-fetchAll($select); } } class Article extends Zend_Db_Table_Row_Abstract { } Is this the wrong way to approach models? Or is there a better way to obtain the fetchAll array of Articles as a return value from the fetchActive() method. Umm... wow... that code is.. wow. First, when you have a Zend_Db_Table object, you already *have* the database adapter -- there's no need to grab it from the registry. Next, Zend_Db_Table also has its own select object now (since 1.5) that obviates the need to (a) pull it from the database adapter, and (b) specify the table name (it's automatically populated). Next, fetchAll() on the adapter already returns an array by default -- it has from the very beginning. You actually have to override this behavior to get a different return type by passing the fetchmode as the second parameter to the call. The reason you're getting anything different is because your code is calling: $db-setFetchMode(Zend_Db::FETCH_OBJ); which tells the adapter to return fetch results as objects. You're basically shooting yourself in the foot here. So, the following will do what you're trying to accomplish: public function fetchActive() { $select = $this-select() -where('active = 1') -order('creation_date DESC'); return $this-getAdapter()-fetchAll($select); } Renan Gonçalves wrote: Hello, How I can use fetchAll with fethMode = Object and using the class Article (for example) ? I can use fetchObject('Article') and will fetch on my class, but in fetchAll the default class is stdClass. The PDOStatement has the function: ( http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php) bool *setFetchMode* ( int $PDO::FETCH_CLASS , string $classname , array $ctorargs ) Best Regards, -- Renan Gonçalves - Web Developer Cell Phone: +55 (11) 8633-6018 MSN: [EMAIL PROTECTED] Web Site: renangoncalves.com São Paulo - SP/Brazil -- View this message in context: http://www.nabble.com/Zend_Db-tp14140524p20373369.html Sent from the Zend Framework mailing list archive at Nabble.com. -- Matthew Weier O'Phinney Software Architect | [EMAIL PROTECTED] Zend Framework | http://framework.zend.com/
Re: [fw-general] Zend_Db_Table_Rowset seek() question
You can use a LimitIterator to make it starts where you want ;-) Julien.P 2008/11/7 Jason Austin [EMAIL PROTECTED] Thanks for the code. After further investigation, it appears that the issue is not with Zend_Db_Table_Rowset, but with the SPL SeekableIterator class, and how PHP handles iterators and foreach loops. The foreach loop executes a rewind() before beginning, therefore resetting our pointer to 0. It would seem to make sense for SeekableIterator to be able to move the pointer, then the foreach loops start where the pointer is telling it to. Zend_Db_Table_Rowset could handle this on its own, but it seems that would be the entire point of implementing SeekableIterator as opposed to Iterator. IE: // in Zend_Db_Table_Rowset_Abstract protected $_seek = false; public function seek($position) { // do all the stuff seek does $this-_seek = true; } public function rewind() { if (!$this-_seek) { $this-_pointer = 0; } $this-_seek = false; return $this; } That code isn't great, but doing something like this could get around PHP's rewind at the beginning of foreach loops, but it seems kinda hack-ish to me. Thoughts? Cameron wrote: I built something like this as a paginator for when you're on your item view. What I did was build a simple class that implements the SPL Iterator and Countable classes, just like the internal Zend_Paginator, but just uses an array as its internal guts. Then I simply grabbed all the id fields from my table and passed it as an array through to my paginator class' constructor, and then called the setCurrentItem method to correctly position the pointer in array. I have no idea if something like this helps you at all, but it seemed a pretty clean way of solving my particular problem, which was getting a next and previous button on my record display. Here's the class anyway, if it helps. class ItemPaginator implements Countable, Iterator { protected $collection; protected $count; protected $pointer_position; public function __construct( $collection ) { $this-collection = $collection; $this-count = sizeof($this-collection); } public function count() { return $this-count; } public function key() { return $this-pointer_position; } public function current() { return $this-collection[$this-pointer_position]; } public function next() {$this-pointer_position++; } public function rewind() { $this-pointer_position = 0; } public function valid() { return strlen( $this-collection ) $this-pointer_position; }public function getNextItem() { if ($this-pointer_position $this-count) { return $this-collection[$this-pointer_position + 1]; } return false; } public function getPrevItem() { if ($this-pointer_position 0 ) { return $this-collection[$this-pointer_position - 1]; } return false; } public function getFirstItem() { if ($this-pointer_position 0 ) { return $this-collection[0]; } return false; } public function getLastItem() { if ($this-pointer_position $this-count ) { return $this-collection[$this-count - 1]; // -1 for the array offset } return false; } public function setCurrentItem($item) { $key = array_search($item, $this-collection); if (FALSE !== $key) { $this-pointer_position = $key; return true; } return false; } } Sorry if this is really terrible code that I should be implementing completely differently, the SPL is all a bit new to me :) On Fri, Nov 7, 2008 at 1:17 AM, Jason Austin [EMAIL PROTECTED]mailto: [EMAIL PROTECTED] wrote: I have a need to paginate some simple results, which I need the count of the entire rowset, and then rows from a particular offset. I don't really want to execute 2 queries, so I was thinking of using the seek() method of my result set to put the pointer to the required offset, however when I loop through the results it starts over at the beginning of the result set: ?php $rows = $model-fetchAll($where, $order); $rows-seek($page * $resultsPerPage); echo $rows-current()-id // echoes correct seek() offset ID foreach ($rows as $r) { // starts over at the beginning of the rowset // add to result set } ? Is this the expected behavior or am I missing something totally obvious? This is with version 1.6.1. http://1.6.1. Should I just do 2 queries (a query to get the required rows, then a count query without qualifier)? Thanks! Jason --Jason Austin Senior Solutions Implementation Engineer NC State University - Office of Information Technology http://webapps.ncsu.edu 919.513-4372 -- Jason
RE: [fw-general] Zend Form Validation
Any help on this? - Nickolas Whiting Developer http://xstudiosinc.com Xstudios -- View this message in context: http://www.nabble.com/Zend-Form-Validation-tp20267185p20382827.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] ZF application optimizations (and speedup)
On Fri, Nov 7, 2008 at 1:36 AM, Sander van de Graaf [EMAIL PROTECTED] wrote: Hi all, Just wanted to point you to a blog post about some optimizations I found for a ZF project we're finishing up. It might be of interest to some of you: http://www.svdgraaf.nl/2008/11/07/optimizing-your-zf-web-application/ If you have any comments, please let me know. Forgot to add this in the comments, YSlow is a real good recommendation. Very simple to use and if you comply, the results are pretty good. We've been trying to please it as well. ;-)) Cheers, Till
Re: [fw-general] ZF application optimizations (and speedup)
On Fri, Nov 7, 2008 at 1:09 PM, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: -- Michael Depetrillo [EMAIL PROTECTED] wrote (on Thursday, 06 November 2008, 09:33 PM -0800): Does using autoload improve or reduce performance? I thought I saw an email by you where you stated in did. It improves performance, particularly when you strip out the require_once calls within Zend Framework (which you can do with a simple one-liner using find and sed). Just to add to this. Yes, and also no. Zend_Loader by itself is faster than all the require_once in the framework. However, it can be simplified still to e.g. using include vs. include_once since autoload is only invoked when the class is not found thus making include_once redundant. Till
[fw-general] Trouble with on Change in Zend_Form_Element_Select
Hey everyone I am working with ZF 1.6.2 and I'm trying to select something from one select element and then enable a second select element. I tried it as follows, but there are two problems. First of all go() does not know $fach2 and if I try to simply echo a random number it shows this one already when loading the page and does not change it when changing the select value. Can anyone help me with this? I would rather not try it with JavaScript, but if there is no other solution, please post this one, too. Thanx! function go() { $fach2-disable = true; //does not know $fach2 //echo random number //srand(); //echo rand(); } public function __construct($options = null) { parent::__construct($options); $this-setAttrib('enctype', 'multipart/form-data'); $this-setName('upload_form'); $fach = new Zend_Form_Element_Select('fach'); $fach-setLabel(Fach:) -setName('fach') -setAttrib('id', 'fach') -setAttrib('onChange', $this-go()); $fach2 = new Zend_Form_Element_Select('fach2'); $fach2-disable = true; $fach2-setLabel(Fach2:) -setName('fach2') -setAttrib('id', 'fach2'); $this-addElements(array($fach, $fach2)); } Would be great if someone could help me. Thanx Mantz -- View this message in context: http://www.nabble.com/Trouble-with-on-Change-in-Zend_Form_Element_Select-tp20383280p20383280.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] ZF quickstart not working?
Hi, Is it just me or quickstart is not working. I got Message: SQLSTATE[HY000]: General error: 14 unable to open database file when I try to submit/add stuff in guestbook. I have chmod 777 data/db/guestbook-dev.db All other success messages etc are working as expected.
Re: [fw-general] ZF quickstart not working?
On Fri, Nov 7, 2008 at 5:04 PM, Julian Davchev [EMAIL PROTECTED] wrote: Hi, Is it just me or quickstart is not working. I got Message: SQLSTATE[HY000]: General error: 14 unable to open database file when I try to submit/add stuff in guestbook. I have chmod 777 data/db/guestbook-dev.db All other success messages etc are working as expected. ORLY? ;-) Make sure the path to the sqlite database is correct. :-) Use an absolute path maybe. Till
Re: [fw-general] Zend PDT 2.0 all-in-one available (BETA)
Hello, I didn't tried it, but I have a Question: How is the JavaScript Editor working? Is it possible to get jQuery or Prototype CodeCompletion? Thanks and Greetings, Stefan Sturm
Re: [fw-general] ZF application optimizations (and speedup)
-- till [EMAIL PROTECTED] wrote (on Friday, 07 November 2008, 03:40 PM +0100): On Fri, Nov 7, 2008 at 1:09 PM, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: -- Michael Depetrillo [EMAIL PROTECTED] wrote (on Thursday, 06 November 2008, 09:33 PM -0800): Does using autoload improve or reduce performance? I thought I saw an email by you where you stated in did. It improves performance, particularly when you strip out the require_once calls within Zend Framework (which you can do with a simple one-liner using find and sed). Just to add to this. Yes, and also no. Zend_Loader by itself is faster than all the require_once in the framework. However, it can be simplified still to e.g. using include vs. include_once since autoload is only invoked when the class is not found thus making include_once redundant. The main reason Zend_Loader uses include_once over include is to ensure that if there are any arbitrary require_once or include_once calls elsewhere in the codebase, they won't lead to a conflict. While you may have stripped them from your Zend Framework install, we cannot assume you've done the same in your userland code. -- Matthew Weier O'Phinney Software Architect | [EMAIL PROTECTED] Zend Framework | http://framework.zend.com/
Re: [fw-general] ZF quickstart not working?
-- Julian Davchev [EMAIL PROTECTED] wrote (on Friday, 07 November 2008, 06:04 PM +0200): Is it just me or quickstart is not working. I got Message: SQLSTATE[HY000]: General error: 14 unable to open database file when I try to submit/add stuff in guestbook. I have chmod 777 data/db/guestbook-dev.db The directory in which the DB file exists also needs to have RW permissions for the apache process. I usually do: chmod -R a+rwX data which ensures that the entire data/ subdirectory has these permissions. All other success messages etc are working as expected. -- Matthew Weier O'Phinney Software Architect | [EMAIL PROTECTED] Zend Framework | http://framework.zend.com/
Re: [fw-general] ZF application optimizations (and speedup)
On Fri, Nov 7, 2008 at 5:42 PM, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: -- till [EMAIL PROTECTED] wrote (on Friday, 07 November 2008, 03:40 PM +0100): On Fri, Nov 7, 2008 at 1:09 PM, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: -- Michael Depetrillo [EMAIL PROTECTED] wrote (on Thursday, 06 November 2008, 09:33 PM -0800): Does using autoload improve or reduce performance? I thought I saw an email by you where you stated in did. It improves performance, particularly when you strip out the require_once calls within Zend Framework (which you can do with a simple one-liner using find and sed). Just to add to this. Yes, and also no. Zend_Loader by itself is faster than all the require_once in the framework. However, it can be simplified still to e.g. using include vs. include_once since autoload is only invoked when the class is not found thus making include_once redundant. The main reason Zend_Loader uses include_once over include is to ensure that if there are any arbitrary require_once or include_once calls elsewhere in the codebase, they won't lead to a conflict. While you may have stripped them from your Zend Framework install, we cannot assume you've done the same in your userland code. True, and true. Did you ever consider benchmarking it against: if (!class_exists($foo)) { include $foo; } I haven't, so I am asking. I was thinking if a lookup in userland can actually outperform all the PHP-goodness. ;-) Also, the thing is, if you recommend that people use Zend_Loader in __autoload(), then using include instead of include_once is somewhat a given since __autoload would never invoke the loader if the class hasn't been loaded already. Right? I know that inside the framework code, there are a ton of instances where Zend_Loader::loadClass() is used to load adapters/drivers etc.. I wish there was a way to register a default loader for the entire framework, so I could use mine everywhere. No idea if that is so hard to implement. Have a great weekend, Till
Re: [fw-general] Re: Having problems using Zend Cache and Flickr
sorry but your two print_r dumps seems to be the same ? can you be more precise and showing us the differences ? I don't know if it's the problem here. But don't forget that PHP serialization doesn't work with resources Ian a écrit : Anyone have an ideas on this? Im still stuck... On Wed, Nov 5, 2008 at 10:26 AM, Ian [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Hi, I am having problems using Zend Cache and Service Flickr. The problem is that the array I get before caching is very different from the cache. Any ideas as to what im doing wrong? Here is my code: require_once('Zend/Loader.php'); Zend_Loader::registerAutoload(); Zend_Loader::loadClass('Zend_Cache'); Zend_Loader::loadClass('Zend_Service_Flickr'); Zend_Loader::loadClasS('Zend_Service_Flickr_ResultSet'); /* Setup cache options */ $frontendOptions = array( 'caching' = true, 'lifetime' = 600, // cache lifetime of 10 minutes 'automatic_serialization' = true ); $backendOptions = array( 'cache_db_complete_path' = '/cache/cache.sqlite' ); /* Init both vars */ $cache = Zend_Cache::factory('Core', 'Sqlite', $frontendOptions, $backendOptions); $flickr = new Zend_Service_Flickr(''); if(!$results = $cache-load('flickrcache')) { $results = $flickr-groupPoolGetPhotos(''); $cache-save($results, 'flickrcache'); } The print_r now shows this when retreived from cache: Zend_Service_Flickr_ResultSet Object ( [totalResultsAvailable] = 215 [totalResultsReturned] = 10 [firstResultPosition] = 1 [_results:protected] = DOMNodeList Object ( ) [_flickr:private] = Zend_Service_Flickr Object ( [apiKey] = [_restClient:protected] = Zend_Rest_Client Object ( [_data:protected] = Array ( ) [_uri:protected] = Zend_Uri_Http Object ( [_username:protected] = [_password:protected] = [_host:protected] = www.flickr.com http://www.flickr.com [_port:protected] = 80 [_path:protected] = /services/rest/ [_query:protected] = [_fragment:protected] = [_regex:protected] = Array ( [alphanum] = [^\W_] [escaped] = (?:%[\da-fA-F]{2}) [mark] = [-_.!~*'()\[\]] [reserved] = [;\/?:@=+$,] [unreserved] = (?:[^\W_]|[-_.!~*'()\[\]]) [segment] = (?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@=+$,;])*) [path] = (?:\/(?:(?:(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})|[:@=+$,;])*)?)+ [uric] = (?:[;\/?:@=+$,]|(?:[^\W_]|[-_.!~*'()\[\]])|(?:%[\da-fA-F]{2})) ) [_scheme:protected] = http ) ) ) [_currentIndex:private] = 0 ) And this when loaded originally: Zend_Service_Flickr_ResultSet Object ( [totalResultsAvailable] = 215 [totalResultsReturned] = 10 [firstResultPosition] = 1 [_results:protected] = DOMNodeList Object ( ) [_flickr:private] = Zend_Service_Flickr Object ( [apiKey] = [_restClient:protected] = Zend_Rest_Client Object ( [_data:protected] = Array ( ) [_uri:protected] = Zend_Uri_Http Object ( [_username:protected] = [_password:protected] = [_host:protected] = www.flickr.com http://www.flickr.com [_port:protected] = 80 [_path:protected] = /services/rest/ [_query:protected] = [_fragment:protected] = [_regex:protected] = Array ( [alphanum] = [^\W_] [escaped] = (?:%[\da-fA-F]{2}) [mark] = [-_.!~*'()\[\]]
Re: [fw-general] Zend_Search_Lucene is very sloooooow
Hi, I did a prototype using ZSL using a database of news articles 40,000. I had a bit of a mixed experience Indexing was fine took a while but nothing unexpected. Searching using simple queries was ok I think its was something like 0.8 - 2 seconds per search Searching using ranges failed sometimes and was slow (probably my config though). Memory usage was a worry as searches seemed to use a lot, I cant remember the figures though. Obviously my prototype was very quick and dirty and in no way is a benchmark of ZSL, however I did decide to use another search solution over ZSL based on this. Thx Keith 2008/11/7 Ralf Eggert [EMAIL PROTECTED]: Hi, no that is not my opinion, that is the one sentence I heard most during the last IPC in Mainz when I talked to others about Zend_Search_Lucene. The widespread belief was that Zend_Search_Lucene is a very nice tool but it is damn slow with a larger index. I need to add that I did not find out if this is related to indexing or searching or both. So how are your experiences with Zend_Search_Lucene regarding performance? Is it really that slow when handling millions of datasets? Which process is slow, the indexing or the searching? Did anyone encounter performance issues with Zend_Search_Lucene and managed to solve it? If yes, how? What about best practices regarding performance. I just built an application yet that only has ~1.000 datasets and I did not notice any issues yet. But maybe someone worked on a much bigger index and can provide us with his or her experiences? Thanks and best regards, Ralf -- -- [MuTe] --
Re: [fw-general] ZF application optimizations (and speedup)
-- till [EMAIL PROTECTED] wrote (on Friday, 07 November 2008, 05:47 PM +0100): On Fri, Nov 7, 2008 at 5:42 PM, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: -- till [EMAIL PROTECTED] wrote (on Friday, 07 November 2008, 03:40 PM +0100): On Fri, Nov 7, 2008 at 1:09 PM, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: -- Michael Depetrillo [EMAIL PROTECTED] wrote (on Thursday, 06 November 2008, 09:33 PM -0800): Does using autoload improve or reduce performance? I thought I saw an email by you where you stated in did. It improves performance, particularly when you strip out the require_once calls within Zend Framework (which you can do with a simple one-liner using find and sed). Just to add to this. Yes, and also no. Zend_Loader by itself is faster than all the require_once in the framework. However, it can be simplified still to e.g. using include vs. include_once since autoload is only invoked when the class is not found thus making include_once redundant. The main reason Zend_Loader uses include_once over include is to ensure that if there are any arbitrary require_once or include_once calls elsewhere in the codebase, they won't lead to a conflict. While you may have stripped them from your Zend Framework install, we cannot assume you've done the same in your userland code. True, and true. Did you ever consider benchmarking it against: if (!class_exists($foo)) { include $foo; } I haven't, so I am asking. I was thinking if a lookup in userland can actually outperform all the PHP-goodness. ;-) Actually... loadClass() already does that. The issue is in the userland code -- if they do a require_once or include_once in userland *after* we've already loaded the class in the autoloader using simply include, that will trigger the error. That's what I was getting at. That said, we may be being to defensive about this. Also, the thing is, if you recommend that people use Zend_Loader in __autoload(), then using include instead of include_once is somewhat a given since __autoload would never invoke the loader if the class hasn't been loaded already. Right? I know that inside the framework code, there are a ton of instances where Zend_Loader::loadClass() is used to load adapters/drivers etc.. I wish there was a way to register a default loader for the entire framework, so I could use mine everywhere. No idea if that is so hard to implement. Zend_Loader::registerAutoload() registers with spl_autoload. -- Matthew Weier O'Phinney Software Architect | [EMAIL PROTECTED] Zend Framework | http://framework.zend.com/
[fw-general] How to return result from this sql?
Hi all, i am stucked with this. I have to transform regular sql into Zend DB sql and then to return values in my phtml file. After many days i am not able to acompish that. There is my indexAction. public function indexAction() { $db = Zend_Registry::get ( 'db' ); $sql = $db-select () -from ( 'bannertype', array ('bannertypeid', 'bannercat', 'bannercatdesc', 'active','bannersacross','view_type' ) ) -where ( 'active = ?', 'y' )-order ( 'bannertypeid','ASC' ); $rez = $sql-query (); $i=-1; while($res = $rez-fetchAll ()){ foreach($res as $key=$value){ $i++; //print_r($res); $banncat= $res[$i]['bannertypeid']; } $this-view-bannerCategorie = $res; $result = $db-fetchAll(SELECT ws.*,b.*,bt.*, (SELECT COUNT(*) FROM banners b WHERE b.websiteid = ws.websiteid AND b.bannertype= '$banncat') AS theCountCategory1, (SELECT bannercat FROM bannertype c WHERE c.bannertypeid= '$banncat') AS theNameCategory1 FROM websites ws left join banners b on b.websiteid=ws.websiteid left join bannertype bt on b.bannertype=bt.bannertypeid where b.bannertype='$banncat' group by ws.websiteid); echo pre;print_r($result);echo /pre;// this gives me an array $this-view-result = $result;// this one returns nothing to phtml :( } } How to pass this result into phtml? Thank you, V -- View this message in context: http://www.nabble.com/How-to-return-result-from-this-sql--tp20377930p20377930.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Database Migrations - Yes, No, Maybe?
Coming to ZF from a Rails background (because I'm much stronger in PHP than in Ruby), one of the things that irks me is the *apparent* lack of a formal database migration system. In Rails, you create migration files, define the structure and/or changes in a DB-neutral context, then run the migration to have the changes made to your database, be it MySQL, Oracle, MSSQL, etc. Does this functionality exist with Zend Framework at all? I haven't seen any mention of it in tutorials or other information, but since I'm new, I figure chances are I'm missing something. If this doesn't exist, is it planned? Thanks.
Re: [fw-general] Zend_Db
I sent my original reply to you, but I'm posting here for the archives. -- Edward Haber [EMAIL PROTECTED] wrote (on Friday, 07 November 2008, 07:09 AM -0500): Thanks for the help! It is much appreciated. I had a feeling I was doing something a bit fishy. I tried the code below and the method is returning an associative array instead of an array of Article objects. If I do change the setFetchMode globally in the bootstrap, it changes to stdClass. Is there a way I can get this method to return an array of Article objects? Aha -- that was the missing bit. By default, if you call fetchAll() on the _table_ object, it returns a Zend_Db_Table_Rowset object, which is simply an iterable object of Row objects. In the class definition you presented, this would mean that it would return a rowset populated by Article objects. The following achieves that: return $this-fetchAll($select); Alternately, if you really, really want to have it return an array instead of a rowset, do the following: $rowset = $this-fetchAll($select); $return = array(); foreach ($rowset as $row) { $return[] = $row; } return $return; Personally, I'd just use the Rowset -- it acts just like an array for all practical intents and purposes. On Nov 6, 2008, at 9:35 PM, Matthew Weier O'Phinney wrote: -- DorkFest [EMAIL PROTECTED] wrote (on Thursday, 06 November 2008, 05:58 PM -0800): This was posted in Dec 2007. I have the same question. Is there anyway using fetchAll and setFetchMode to set the explicit class name that's returned in the array? Or is this a design conflict? Here's basically the situation: class Articles extends Zend_Db_Table_Abstract { protected $_name = articles; protected $_rowClass = Article; public function fetchActive() { $db = Zend_Registry::get('db'); $db-setFetchMode(Zend_Db::FETCH_OBJ); $select = $db-select() -from($this-_name) -where('active = 1') -order('creation_date DESC'); // want to return array of articles objects here instead of stdClass return $db-fetchAll($select); } } class Article extends Zend_Db_Table_Row_Abstract { } Is this the wrong way to approach models? Or is there a better way to obtain the fetchAll array of Articles as a return value from the fetchActive() method. Umm... wow... that code is.. wow. First, when you have a Zend_Db_Table object, you already *have* the database adapter -- there's no need to grab it from the registry. Next, Zend_Db_Table also has its own select object now (since 1.5) that obviates the need to (a) pull it from the database adapter, and (b) specify the table name (it's automatically populated). Next, fetchAll() on the adapter already returns an array by default -- it has from the very beginning. You actually have to override this behavior to get a different return type by passing the fetchmode as the second parameter to the call. The reason you're getting anything different is because your code is calling: $db-setFetchMode(Zend_Db::FETCH_OBJ); which tells the adapter to return fetch results as objects. You're basically shooting yourself in the foot here. So, the following will do what you're trying to accomplish: public function fetchActive() { $select = $this-select() -where('active = 1') -order('creation_date DESC'); return $this-getAdapter()-fetchAll($select); } Renan Gonçalves wrote: Hello, How I can use fetchAll with fethMode = Object and using the class Article (for example) ? I can use fetchObject('Article') and will fetch on my class, but in fetchAll the default class is stdClass. The PDOStatement has the function: ( http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php) bool *setFetchMode* ( int $PDO::FETCH_CLASS , string $classname , array $ctorargs ) -- Matthew Weier O'Phinney Software Architect | [EMAIL PROTECTED] Zend Framework | http://framework.zend.com/
Re: [fw-general] Database Migrations - Yes, No, Maybe?
does not exist and is not planned from what i can see in the proposals (there is one proposal, but its inactive for many months). if you want to use a formal migration system use Doctrine, Propel or ezcDatabaseSchema. All great components. Since ZF does not enforce a model component on you, its very easy to switch them in. Benjamin On Friday 07 November 2008 19:15:24 Phoenix wrote: Coming to ZF from a Rails background (because I'm much stronger in PHP than in Ruby), one of the things that irks me is the *apparent* lack of a formal database migration system. In Rails, you create migration files, define the structure and/or changes in a DB-neutral context, then run the migration to have the changes made to your database, be it MySQL, Oracle, MSSQL, etc. Does this functionality exist with Zend Framework at all? I haven't seen any mention of it in tutorials or other information, but since I'm new, I figure chances are I'm missing something. If this doesn't exist, is it planned? Thanks. -- Benjamin Eberlei http://www.beberlei.de
Re: [fw-general] Zend_Filter classes turn NULL values into empty strings
Well, you can create a new Filter, which converts empty strings into null and add it to the the form Grotevant, Paul F escreveu: I'm developing a Zend_Form class which will feed data into a MySQL table through a Zend_Db table class. There are a number of fields on this form that are optional, and which I want to default to NULL in the database if they are not filled in. However, I was finding that the empty values from the form were being inserted into the db table as empty strings, rather than NULLs (this was true even if those fields were disabled, meaning that there were no values for them in the POST data -- $form-getValues() returns zero-length strings rather than NULLs). After some head-scratching, I realized that it was the StringTrim and HtmlEntities filters that were turning those fields into zero-length strings, which by turn get inserted into the db table as zero-length strings instead of NULL. I can take the filters off of those form elements and get the desired result in my database, but that leaves me with a form that's potentially vulnerable to cross-site scripting attacks. Any thoughts? Thanks, Paul -- Felipe Weckx [EMAIL PROTECTED] MT4 Tecnologia (11) 3064-3226
Re: [fw-general] Zend_Search_Lucene is very sloooooow
Your e-mail prompted me to finally write down my thoughts on the subject: http://www.builtfromsource.com/2008/11/07/zend_search_lucene-not-enterprise-ready/ -Matt On Fri, Nov 7, 2008 at 1:09 AM, Ralf Eggert [EMAIL PROTECTED] wrote: Hi, no that is not my opinion, that is the one sentence I heard most during the last IPC in Mainz when I talked to others about Zend_Search_Lucene. The widespread belief was that Zend_Search_Lucene is a very nice tool but it is damn slow with a larger index. I need to add that I did not find out if this is related to indexing or searching or both. So how are your experiences with Zend_Search_Lucene regarding performance? Is it really that slow when handling millions of datasets? Which process is slow, the indexing or the searching? Did anyone encounter performance issues with Zend_Search_Lucene and managed to solve it? If yes, how? What about best practices regarding performance. I just built an application yet that only has ~1.000 datasets and I did not notice any issues yet. But maybe someone worked on a much bigger index and can provide us with his or her experiences? Thanks and best regards, Ralf
Re: [fw-general] Database Migrations - Yes, No, Maybe?
This is something that I expect we'll see after Zend_Tool is completed and we approach 2.0, along with generators. Trust me, I want to see those things, too. :-) -Matt On Fri, Nov 7, 2008 at 10:41 AM, Benjamin Eberlei [EMAIL PROTECTED]wrote: does not exist and is not planned from what i can see in the proposals (there is one proposal, but its inactive for many months). if you want to use a formal migration system use Doctrine, Propel or ezcDatabaseSchema. All great components. Since ZF does not enforce a model component on you, its very easy to switch them in. Benjamin On Friday 07 November 2008 19:15:24 Phoenix wrote: Coming to ZF from a Rails background (because I'm much stronger in PHP than in Ruby), one of the things that irks me is the *apparent* lack of a formal database migration system. In Rails, you create migration files, define the structure and/or changes in a DB-neutral context, then run the migration to have the changes made to your database, be it MySQL, Oracle, MSSQL, etc. Does this functionality exist with Zend Framework at all? I haven't seen any mention of it in tutorials or other information, but since I'm new, I figure chances are I'm missing something. If this doesn't exist, is it planned? Thanks. -- Benjamin Eberlei http://www.beberlei.de
[fw-general] Handling asset version control with ZF
Hey, I am looking for some creative and efficent ideas on how to handle static asset control using ZF for a large scale app. When I say static assets I am refering to: static images js scripts uploaded images/thumbnails css files I am currently hosting these on a seperate domain name from my application. I was thinking about adding a version number to each filename and incrementing this number everytime the image is updated.. However, this would result in me having to go through all the code and change the filename for any updates.. This wouldn't be that hard.. I am just wondering if anyone has more creative ways to handle this. Thanks -- View this message in context: http://www.nabble.com/Handling-asset-version-control-with-ZF-tp20387128p20387128.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Filter classes turn NULL values into empty strings
i have the same problem, will try this, though i'd rather not have to write a new filter. Felipe Weckx-2 wrote: Well, you can create a new Filter, which converts empty strings into null and add it to the the form Grotevant, Paul F escreveu: I'm developing a Zend_Form class which will feed data into a MySQL table through a Zend_Db table class. There are a number of fields on this form that are optional, and which I want to default to NULL in the database if they are not filled in. However, I was finding that the empty values from the form were being inserted into the db table as empty strings, rather than NULLs (this was true even if those fields were disabled, meaning that there were no values for them in the POST data -- $form-getValues() returns zero-length strings rather than NULLs). After some head-scratching, I realized that it was the StringTrim and HtmlEntities filters that were turning those fields into zero-length strings, which by turn get inserted into the db table as zero-length strings instead of NULL. I can take the filters off of those form elements and get the desired result in my database, but that leaves me with a form that's potentially vulnerable to cross-site scripting attacks. Any thoughts? Thanks, Paul -- Felipe Weckx [EMAIL PROTECTED] MT4 Tecnologia (11) 3064-3226 -- View this message in context: http://www.nabble.com/Zend_Filter-classes-turn-NULL-values-into-empty-strings-tp20374949p20388548.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Mail how to test text/html bodies
Hi All, I've been using the: $mail-setBodyText(); $mail-setBodyHtml(); To set alternate bodies to my emails. I've sorta always taken it on faith that these work. But I figured I should probably test it. So how do you test the text body of an email? I tried pine once I think for a different mail library and it showed the HTML body (tags and all). Thanks, Mark
Re: [fw-general] Handling asset version control with ZF
http://en.wikipedia.org/wiki/Revision_control -Matt On Fri, Nov 7, 2008 at 11:33 AM, j5 [EMAIL PROTECTED] wrote: Hey, I am looking for some creative and efficent ideas on how to handle static asset control using ZF for a large scale app. When I say static assets I am refering to: static images js scripts uploaded images/thumbnails css files I am currently hosting these on a seperate domain name from my application. I was thinking about adding a version number to each filename and incrementing this number everytime the image is updated.. However, this would result in me having to go through all the code and change the filename for any updates.. This wouldn't be that hard.. I am just wondering if anyone has more creative ways to handle this. Thanks -- View this message in context: http://www.nabble.com/Handling-asset-version-control-with-ZF-tp20387128p20387128.html Sent from the Zend Framework mailing list archive at Nabble.com.
RE: [fw-general] Database Migrations - Yes, No, Maybe?
If I'm not mistaken, Rob Allen originally proposed DB migrations some time back. Last I heard, he was planning to refactor that proposal to build on Zend_Tool. Rob, how off am I? ,Wil -Original Message- From: Benjamin Eberlei [mailto:[EMAIL PROTECTED] Sent: Friday, November 07, 2008 10:41 AM To: fw-general@lists.zend.com Subject: Re: [fw-general] Database Migrations - Yes, No, Maybe? does not exist and is not planned from what i can see in the proposals (there is one proposal, but its inactive for many months). if you want to use a formal migration system use Doctrine, Propel or ezcDatabaseSchema. All great components. Since ZF does not enforce a model component on you, its very easy to switch them in. Benjamin On Friday 07 November 2008 19:15:24 Phoenix wrote: Coming to ZF from a Rails background (because I'm much stronger in PHP than in Ruby), one of the things that irks me is the *apparent* lack of a formal database migration system. In Rails, you create migration files, define the structure and/or changes in a DB-neutral context, then run the migration to have the changes made to your database, be it MySQL, Oracle, MSSQL, etc. Does this functionality exist with Zend Framework at all? I haven't seen any mention of it in tutorials or other information, but since I'm new, I figure chances are I'm missing something. If this doesn't exist, is it planned? Thanks. -- Benjamin Eberlei http://www.beberlei.de
Re: [fw-general] ZF application optimizations (and speedup)
On Fri, Nov 7, 2008 at 12:15 PM, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: Actually... loadClass() already does that. The issue is in the userland code -- if they do a require_once or include_once in userland *after* we've already loaded the class in the autoloader using simply include, that will trigger the error. That's what I was getting at. That said, we may be being to defensive about this. So, if your worried about includes -after- the autoloaded... what exactly are you preventing with include_once? Seems like it'll be an error regardless, no? Regards, Eric
Re: [fw-general] Database Migrations - Yes, No, Maybe?
On 7 Nov 2008, at 21:47, Wil Sinclair wrote: If I'm not mistaken, Rob Allen originally proposed DB migrations some time back. Last I heard, he was planning to refactor that proposal to build on Zend_Tool. Rob, how off am I? That's the basic plan - Zend_Tool is the obvious vehicle to use now. (Once I fully understand it's internals!) I didn't expect Zend Framework in Action to take quite as long as it has done though, which is why it's languished as long as it has. I have high hopes to have the time to look at it properly early next year though! Regards, Rob...
[fw-general] PHP/Apache context
Hi. I'm a newbie at both PHP and Zend. I've just been working on these for the past couple of months. My goal here is to ensure that my understanding of the execution model of PHP under apache is correct, and hopefully get some pointers on speeding things up. Firebug is showing that it takes 300 milliseconds to show one of my pages, which is basically just displaying a form. I figured out how to use xdebug's profiler, and fed the result into kcachegrind, and found that about 30% of that time is used to get table metadata from the database. I think I know how to optimize that using the Cache which is described in the DbTable manual. But, it did get me thinking about the way the execution model of PHP. Let me describe what I understand - hopefully you can correct me if I'm wrong. 1) I'm using the standard debian apache, built with the prefork mpm. It's set to start 5 child processes. 2) Each of those child processes runs their own PHP runtime. 3) There's no PHP magic which automatically shares any context between these runtimes. (except for php's session extension, which seems to have a memory map capability) 4) Every time a request comes in, it goes through my /index.php, and bootstrap, as if it's the first time ever. They don't get any context from any previous inivocations. 5) Most examples show that you can stuff things the registry, but even that doesn't persist over multiple requests. 6) I assume that the PHP runtime is not totally reinitialized between requests, but perhaps only variables are erased. Here are my main questions: a) Is there any way to store a variable (I'm thinking things like database handles, config objects) such that it can be retrieved in the same apache process when it is processing the next request (not using session, since that's specific to a user). b) Is there a way to store a variable such that it is visible in all apache processes through shared memory. I am aware that its possible to serialize things out manually and perhaps use the Cache system, but I am looking for a more direct method of sharing variables. (There doesn't seem to be support for these features in Zend Platform either, right?) Thanks Steve -- View this message in context: http://www.nabble.com/PHP-Apache-context-tp20389722p20389722.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] ZF application optimizations (and speedup)
-- Eric Coleman [EMAIL PROTECTED] wrote (on Friday, 07 November 2008, 05:15 PM -0500): On Fri, Nov 7, 2008 at 12:15 PM, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: Actually... loadClass() already does that. The issue is in the userland code -- if they do a require_once or include_once in userland *after* we've already loaded the class in the autoloader using simply include, that will trigger the error. That's what I was getting at. That said, we may be being to defensive about this. So, if your worried about includes -after- the autoloaded... what exactly are you preventing with include_once? Seems like it'll be an error regardless, no? I'm worried about include_once/require_once() after autoloading. include() and require() will be an issue regardless, but if we can play nice with include_once/require_once(), then we should. That said, we can probably have a flag for using include vs include_once that could be passed to registerAutoload(). -- Matthew Weier O'Phinney Software Architect | [EMAIL PROTECTED] Zend Framework | http://framework.zend.com/
Re: [fw-general] PHP/Apache context
Your understanding is correct. I'm guessing you come from a Java background, or something similar. PHP has no application server concept. The long and short is that there is nothing like what you want, but daemons like memcached can approximate this effect. Serialize data to memory, unserialize on subsequent requests. There is a memcached adapter for Zend_Cache that works using the PECL memcache extension. When serializing data, keep in mind that object relationships do not get serialized, so you must write custom serialization methods to store all the data necessary to recreate the object from scratch (see the __sleep() and __wakeup() magic methods). This is not as tedious as it sounds at first once you understand how everything works together. Hope that helps, -Matt On Fri, Nov 7, 2008 at 2:49 PM, stevep98 [EMAIL PROTECTED] wrote: Hi. I'm a newbie at both PHP and Zend. I've just been working on these for the past couple of months. My goal here is to ensure that my understanding of the execution model of PHP under apache is correct, and hopefully get some pointers on speeding things up. Firebug is showing that it takes 300 milliseconds to show one of my pages, which is basically just displaying a form. I figured out how to use xdebug's profiler, and fed the result into kcachegrind, and found that about 30% of that time is used to get table metadata from the database. I think I know how to optimize that using the Cache which is described in the DbTable manual. But, it did get me thinking about the way the execution model of PHP. Let me describe what I understand - hopefully you can correct me if I'm wrong. 1) I'm using the standard debian apache, built with the prefork mpm. It's set to start 5 child processes. 2) Each of those child processes runs their own PHP runtime. 3) There's no PHP magic which automatically shares any context between these runtimes. (except for php's session extension, which seems to have a memory map capability) 4) Every time a request comes in, it goes through my /index.php, and bootstrap, as if it's the first time ever. They don't get any context from any previous inivocations. 5) Most examples show that you can stuff things the registry, but even that doesn't persist over multiple requests. 6) I assume that the PHP runtime is not totally reinitialized between requests, but perhaps only variables are erased. Here are my main questions: a) Is there any way to store a variable (I'm thinking things like database handles, config objects) such that it can be retrieved in the same apache process when it is processing the next request (not using session, since that's specific to a user). b) Is there a way to store a variable such that it is visible in all apache processes through shared memory. I am aware that its possible to serialize things out manually and perhaps use the Cache system, but I am looking for a more direct method of sharing variables. (There doesn't seem to be support for these features in Zend Platform either, right?) Thanks Steve -- View this message in context: http://www.nabble.com/PHP-Apache-context-tp20389722p20389722.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] PHP/Apache context
-- stevep98 [EMAIL PROTECTED] wrote (on Friday, 07 November 2008, 02:49 PM -0800): Here are my main questions: a) Is there any way to store a variable (I'm thinking things like database handles, config objects) such that it can be retrieved in the same apache process when it is processing the next request (not using session, since that's specific to a user). Yes and no. memcached, APC, and Zend Platform all offer caching abilities, as does, in a more limited fashion, PHP's shm support. However, you're limited in what you can cache. It's typically not a great idea to cache actual objects, and you *can't* cache DB handles and other resources. Application and/or configuration data are good targets for caching. b) Is there a way to store a variable such that it is visible in all apache processes through shared memory. Yes -- see the above answer. I am aware that its possible to serialize things out manually and perhaps use the Cache system, but I am looking for a more direct method of sharing variables. (There doesn't seem to be support for these features in Zend Platform either, right?) Caching is the way to go here. Zend_Cache has a variety of backends, targetting each of the systems I mentioned above, and this is a tried and true methodology for scaling your applications. While you may think of the Zend_Cache object as overhead, if your caching strategy is good, it's much less overhead than the alternative. Caching is a fine art -- you have to examine what your expensive operations are, whether they can be cached, and if so, for how long. This sort of thing requires a good knowledge of your systems, your application, and the amount of traffic you receive. -- Matthew Weier O'Phinney Software Architect | [EMAIL PROTECTED] Zend Framework | http://framework.zend.com/
Re: [fw-general] ZF application optimizations (and speedup)
Hi! Actually... loadClass() already does that. The issue is in the userland code -- if they do a require_once or include_once in userland *after* we've already loaded the class in the autoloader using simply include, that will trigger the error. That's what I was getting at. That said, AFAIK include_once does not include file previously included by include/require. -- Stanislav Malyshev, Zend Software Architect [EMAIL PROTECTED] http://www.zend.com/ (408)253-8829 MSN: [EMAIL PROTECTED]
Re: [fw-general] PHP/Apache context
Thanks for your replies, and you're right that I come from a java background. The profiler shows than another source of overhead for me seems to be Zend_Load. Loading all those helper classes takes about 30% of my total request time. I'm guessing the overhead is from actually doing the parsing of those PHP files. I can't help thinking that PHP can make enormous strides in performance by implementing some kind of persistence between sessions. I will certainly be looking more at Zend_Cache, and probably use a memcached backend in the end. But I'm disappointed that Zend_Cache is not built into DB_Table. Certainly, you don't want it on by default, but having it as an option would be good. Especially if cache invalidation is hooked into the Row save() method. Thanks again, anyway! Steve -- View this message in context: http://www.nabble.com/PHP-Apache-context-tp20389722p20392269.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] PHP/Apache context
The profiler shows than another source of overhead for me seems to be Zend_Load. Loading all those helper classes takes about 30% of my total request time. I'm guessing the overhead is from actually doing the parsing of those PHP files. It's likely that you're not doing everything you can to improve this. First, use APC. Second, use Zend_Loader::registerAutoload() and make the following shell command part of the build process for importing Zend Framework: find . -name '*.php' -print0 | xargs -0 sed --regexp-extended --in-place 's/(require_once/\/\/ \1/g' Third, make sure that your library directory (including Zend) comes at the beginning of your include path, not at the end. Benchmark requests per second before and after doing these things and I think you'll see a significant increase. -Matt On Fri, Nov 7, 2008 at 6:27 PM, stevep98 [EMAIL PROTECTED] wrote: Thanks for your replies, and you're right that I come from a java background. The profiler shows than another source of overhead for me seems to be Zend_Load. Loading all those helper classes takes about 30% of my total request time. I'm guessing the overhead is from actually doing the parsing of those PHP files. I can't help thinking that PHP can make enormous strides in performance by implementing some kind of persistence between sessions. I will certainly be looking more at Zend_Cache, and probably use a memcached backend in the end. But I'm disappointed that Zend_Cache is not built into DB_Table. Certainly, you don't want it on by default, but having it as an option would be good. Especially if cache invalidation is hooked into the Row save() method. Thanks again, anyway! Steve -- View this message in context: http://www.nabble.com/PHP-Apache-context-tp20389722p20392269.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] ZF application optimizations (and speedup)
That's correct. A file included with either include or include_once will not be loaded again if the interpreter hits a subsequent include_once statement. -Matt On Fri, Nov 7, 2008 at 6:15 PM, Stanislav Malyshev [EMAIL PROTECTED] wrote: Hi! Actually... loadClass() already does that. The issue is in the userland code -- if they do a require_once or include_once in userland *after* we've already loaded the class in the autoloader using simply include, that will trigger the error. That's what I was getting at. That said, AFAIK include_once does not include file previously included by include/require. -- Stanislav Malyshev, Zend Software Architect [EMAIL PROTECTED] http://www.zend.com/ (408)253-8829 MSN: [EMAIL PROTECTED]
Re: [fw-general] PHP/Apache context
-- stevep98 [EMAIL PROTECTED] wrote (on Friday, 07 November 2008, 06:27 PM -0800): Thanks for your replies, and you're right that I come from a java background. The profiler shows than another source of overhead for me seems to be Zend_Load. Loading all those helper classes takes about 30% of my total request time. I'm guessing the overhead is from actually doing the parsing of those PHP files. I can't help thinking that PHP can make enormous strides in performance by implementing some kind of persistence between sessions. I've been doing some performance profiling and benchmarking for the 1.7.0 release, and started writing a performance appendix to the manual. The first chapter in it is on class loading, as, like you, I identified it as a major bottleneck. There are a number of ways to make things faster. As Matthew Ratzloff noted, you can comment out all the require_once calls and use autoloading, which saves some significant overhead. Additionally, I've added some functionality for 1.7.0 that will help with plugin loading -- an include file cache for Zend_Loader_PluginLoader. This piece alone, without autoloading or stripping require_once calls, can give up to a 30% boost in performance without even utilizing an opcode cache. That's another piece anyone serious about performance should be doing, by the way. Unlike Java, PHP is not a compiled language. However, the PHP interpreter does compile the language into opcodes, and these can be cached. APC and Zend Platform are excellent choices for opcode caching. I will certainly be looking more at Zend_Cache, and probably use a memcached backend in the end. But I'm disappointed that Zend_Cache is not built into DB_Table. Certainly, you don't want it on by default, but having it as an option would be good. Especially if cache invalidation is hooked into the Row save() method. Caching strategies differ between applications. We opted to leave it to the developer to determine when and where to cache. Additionally, you may have other items you want to trigger at save() time -- reindexing a record for you Lucene index, triggering notification emails, etc. A proposal to add a plugin architecture to Zend_Db_Table has been developed in the incubator, but the developers have been unable to complete unit testing and documentation of it; after 1.7.0, I plan to push it to completion, as it would make this sort of thing easier. We could then offer standard plugins for caching, indexing, etc. that would be opt-in. -- Matthew Weier O'Phinney Software Architect | [EMAIL PROTECTED] Zend Framework | http://framework.zend.com/