[PHP] headers: setting right for browser to force reload at a certain point in time
Hi All, We have an application that generates dynamic ebooks. One of the (minor) problems (but yet annoying) is that when a user comes back to an ebook, they have to actually delete the cache and reload the page to not get the cached version which might be wrong because the content or even the flash application is updated. It would be neat if we could force a reload of the page, but only with a special condition like the ebook being updated or the swf. The swf and also the other resources are not reloaded though, because it is a get request. Is there a way to force a reload of the browser by maybe changing the headers? Or do we have to do some fancy stuff like storing a cookie with the time and sending it back via ajax or something like that? Just setting the header would be nice... Maybe the easiest would be to change the link (add a number or something) of the html page and have a rewrite for all the relative urls as well. Regards, Tim Tim-Hinnerk Heuer http://www.ihostnz.com Henny Youngman - When I told my doctor I couldn't afford an operation, he offered to touch-up my X-rays.
Re: [PHP] PHP - user profile page with pic
--- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com -- On Mon, Feb 23, 2009 at 12:25 PM, Jeffery Harris jhar...@harris4interactive.com wrote: my level of coding is basic. out of the box is fine as long as it is a good one. I do know how to connect to database pull and display records as well as set up login. But I guess I have to create a session so that when a user logs in only his/her information is shown correct? Yes, and it would be better for you to have an in depth look into the open source projects found. Get to analyse them. So, you'll get familiarized with the advanced well known methods. Learning from them you will be able to create something better and not reinventing the wheels. Lenin -Jeff - Original Message - From: 9el le...@phpxperts.net Newsgroups: php.general To: jeffery harris jhar...@harris4interactive.cm Cc: php-general@lists.php.net Sent: Thursday, February 19, 2009 12:40 AM Subject: Re: [PHP] PHP - user profile page with pic The question can be equally rephrased as How an Atom bom/Spaceship be created? Answer depends on the level of knowledge you have on coding / developing sites. Woud you be using any framework? or would you use any readymade CMS? Or write everything from scratch? Question can also be generalized further like would php be your developing language? Or you'd develop your own new language out of the box. :) --- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com -- On Thu, Feb 19, 2009 at 9:46 AM, jeffery harris jhar...@harris4interactive.com wrote: Any ideas or tutorials on how to build a user profile page sort of like facebook? -Jeff -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] headers: setting right for browser to force reload at a certain point in time
German Geek wrote: Hi All, We have an application that generates dynamic ebooks. One of the (minor) problems (but yet annoying) is that when a user comes back to an ebook, they have to actually delete the cache and reload the page to not get the cached version which might be wrong because the content or even the flash application is updated. Deleting the cache should not be necessary, a reload should be enough. (it certainly is with Firefox). It would be neat if we could force a reload of the page, but only with a special condition like the ebook being updated or the swf. The swf and also the other resources are not reloaded though, because it is a get request. The request type has nothing to do with it - the browser will do a conditional GET if the local copy is expired. Just set the right expiry time on your files when you serve them, then they will automatically be checked by the browser. /Per -- Per Jessen, Zürich (2.8°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] headers: setting right for browser to force reload at a certain point in time
Yes, that's what i thought, but with my FF 3.0 the resources (swf,png,jpg) don't get reloaded. I have to reload the page (after deleting cache). Something to do with the Apache configuration? ?? Thanks for the reply. Tim-Hinnerk Heuer http://www.ihostnz.com Laurence J. Peter - If two wrongs don't make a right, try three. 2009/2/23 Per Jessen p...@computer.org German Geek wrote: Hi All, We have an application that generates dynamic ebooks. One of the (minor) problems (but yet annoying) is that when a user comes back to an ebook, they have to actually delete the cache and reload the page to not get the cached version which might be wrong because the content or even the flash application is updated. Deleting the cache should not be necessary, a reload should be enough. (it certainly is with Firefox). It would be neat if we could force a reload of the page, but only with a special condition like the ebook being updated or the swf. The swf and also the other resources are not reloaded though, because it is a get request. The request type has nothing to do with it - the browser will do a conditional GET if the local copy is expired. Just set the right expiry time on your files when you serve them, then they will automatically be checked by the browser. /Per -- Per Jessen, Zürich (2.8°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] headers: setting right for browser to force reload at a certain point in time
German Geek wrote: Yes, that's what i thought, but with my FF 3.0 the resources (swf,png,jpg) don't get reloaded. I have to reload the page (after deleting cache). Something to do with the Apache configuration? Hi Tim, Try loading up just a single file in FF - one of your graphics for instance - then hit Ctrl-i to get the info page. That will tell you exactly how FF sees the file - expiry time etc. /Per -- Per Jessen, Zürich (2.6°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] optimizing space for array of booleans
Some languages allows to bit-pack structures to save spaces. Since PHP doesn't have native set data type and operations, will array of booleans be optimized as such? If not, how can I achieve the same result? I need to save about 200 boolean values and I guess it's a good idea to use bitsets. Requirements: - Easy to use (set, unset, test), so C way to use bitwise operations is simply rejected. I need something like Pascal's set. - Small space (bit level if possible) -- View this message in context: http://www.nabble.com/optimizing-space-for-array-of-booleans-tp22159131p22159131.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] headers: setting right for browser to force reload at a certain point in time
2009/2/23 Per Jessen p...@computer.org German Geek wrote: Yes, that's what i thought, but with my FF 3.0 the resources (swf,png,jpg) don't get reloaded. I have to reload the page (after deleting cache). Something to do with the Apache configuration? Hi Tim, Try loading up just a single file in FF - one of your graphics for instance - then hit Ctrl-i to get the info page. That will tell you exactly how FF sees the file - expiry time etc. Hi Per, Thanks. But: This didn't work. ctrl+i brought up my bookmarks. ?? Do i need a special plugin/extension? Have web developer etc. I have Firebug but in the net tab the cached resources don't show up when reloading the page, i guess because they are not reloaded... So, i can't think of a way how to see that information when it is in cache. I had followed some examples on the web talking about the e-tag header which changes the checksum when the file changes, also i remember setting the expiry to yesterday and things like that... However it all didn't work. Anyway, i might just force a reload by changing the links every time dynamically, although it seems a bit overkill :-S. Tim-Hinnerk Heuer http://www.ihostnz.com P. J. O'Rourke - Everybody knows how to raise children, except the people who have them. /Per -- Per Jessen, Zürich (2.6°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] headers: setting right for browser to force reload at a certain point in time
German Geek wrote: This didn't work. ctrl+i brought up my bookmarks. ?? Do i need a special plugin/extension? Have web developer etc. Nope, this is standard FF. Ctrl+i should give you the Page Info window. Try looking for that in your menubar and pulldowns. -- Per Jessen, Zürich (3.1°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] redirecting output for a spawned child process..
You can use a PHP workarround. Install a custom ob_handler, that has a static file descriptor, and writes all output to the file. In order to also see everything, you need to also activate implicit flush. i know that there would be lots of elegant ways to do this on linux in C, but AFAIK php doesn't ofer anything like that. here's some code (untested) ?php function _myObHandler($sBuf) { static $rFile = null; if ($rFile === null) { /// open the file here } fwrite($rFile,$sBuf); return $sBuf; } ob_start('_myObHandler'); ob_implicit_flush(); 2009/2/21 Per Jessen p...@computer.org bruce wrote: hi... got a situation where i have a parent app that spawns children. trying to figure out how to get the output of the spawned/forked children to be written to an external file... Normally I would use freopen() on stdout and stderr, but that's not available in PHP :-( can't seem to find any examples of how to accomplish this... do i have to insert something within the child php app itself to redirect the output that's currently being sent to the term? i'd prefer to have the output displayed, as well as redirected... You basically need to do something about the stdin, stdout and stderr file descriptors that your child inherited from the parent at time of fork(). I can't seem to find many PHP functions that deal with file descriptors though. -- Per Jessen, Zürich (2.6°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Alpar Torok
[PHP] ms-word reading from PHP on linux O.S
Hi all, * How better, i can read ms-word doc files from PHP on LINUX OS*.On searching I got *catdoc* softaware.By using this i can read word doc data as a text. function catdoc_file($fname) { $ret = exec('catdoc -ab '.escapeshellarg($fname) .' 21'); if (preg_match('/^sh: line 1: catdoc/i',$ret)) { return false; } return trim($ret); } It is working well. *Is there are any other softwares that can fetch text from MS-WORD file?.*
RE: [PHP] ms-word reading from PHP on linux O.S
From: Srinivasa Rao D * How better, i can read ms-word doc files from PHP on LINUX OS*.On searching I got *catdoc* softaware.By using this i can read word doc data as a text. It would be helpful to have a little more context. What do you want to do with the text you read this way? When I run across a MS-Word document, my browser is configured to download it to disk. Then I open it with OpenOffice.write and extract what I need. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] adding whitespace to a timestamp
On Sat, Feb 21, 2009 at 1:28 PM, Eric Sherman copyedit...@gmail.com wrote: I hoping to add a space between the date and the time in this: $thedate = date('M jS g:i A', $postTIME); i.e, between* jS* and *g:i* I've looked around but can't find anything. Thanks Eric Sherman Multi Media Information You can put spaces anywhere in that string you want them. What problem are you having? ?php $thedate = date(' M j Sg : i A ', $postTIME); ? Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] optimizing space for array of booleans
Some languages allows to bit-pack structures to save spaces. Since PHP doesn't have native set data type and operations, will array of booleans be optimized as such? If not, how can I achieve the same result? I need to save about 200 boolean values and I guess it's a good idea to use bitsets. Requirements: - Easy to use (set, unset, test), so C way to use bitwise operations is simply rejected. I need something like Pascal's set. - Small space (bit level if possible) -- View this message in context: http://www.nabble.com/optimizing-space-for-array-of-booleans-tp22159131p22159131.html Sent from the PHP - General mailing list archive at Nabble.com. hi, you should not worry about optimizing boolean values unless you would store them in database. anyways, use bitwise operators http://ph.php.net/language.operators.bitwise virgil http://www.jampmark.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] multiple choice dropdown box puzzle
I think this is a tough one... and way above my head: PLEASE READ ALL OF THE ABOVE TO UNDERSTAND WHAT I AM TRYING TO DO. Having a bit of a rough time figuring out how to formulate php-mysql to insert data into fields using a multiple dropdown box in a form. to post I am using the following: snip... $categoriesIN = $_POST[categoriesIN]; ...snip... select name=$categoriesIN[] multiple=multiple OPTIONChoose Categories.../option OPTION VALUE=? echo $categoriesIN; ?1 OPTION VALUE=? echo $categoriesIN; ?2 OPTION VALUE=? echo $categoriesIN; ?3 OPTION VALUE=? echo $categoriesIN; ?4 OPTION VALUE=? echo $categoriesIN; ?5 /SELECT ...snip... $sql4 = FOR ( $ii = 0 ; $ii count($categoriesIN) ; $ii++ ) INSERT INTO temp (example) $categoriesIN[$ii] ; $result4 = mysql_query($sql4, $db); ...snip this does not work! The other posts work like a charm... but this... I cannot figure out what I should be entering where... I have tried several different configurations, but nothing seems to work... I found this as a model for entering the selections but can't figure out how to modify it for my needs: select name=branch_no[] multiple=multiple size=5 option Choose your location(s) /option option value=31003100/option option value=31053105/option option value=3503 3503/option option value=3504 3504/option /select What I would like to do is something like the following: select name=$categoriesIN[] multiple=multiple OPTIONChoose Categories.../option OPTION VALUE=1History OPTION VALUE=2Temples OPTION VALUE=2Pharaohs and Queens OPTION VALUE=4Cleopatra OPTION VALUE=4Mummies /SELECT and going further, I would like to be able to use a table that actually holds these values to feed them to the code above. I am sure this is possible but it must take some huge knowledge and experience to do it. BUT ... as I look at things, I am wondering if the FOR statement in the above should be used to do several INSERTs, that is, one $sql(number) per selected category... now, would that require many $sqls or many INSERTs within the $sql ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] multiple choice dropdown box puzzle
On Mon, Feb 23, 2009 at 10:25 AM, PJ af.gour...@videotron.ca wrote: I think this is a tough one... and way above my head: PLEASE READ ALL OF THE ABOVE TO UNDERSTAND WHAT I AM TRYING TO DO. Having a bit of a rough time figuring out how to formulate php-mysql to insert data into fields using a multiple dropdown box in a form. to post I am using the following: snip... $categoriesIN = $_POST[categoriesIN]; ...snip... select name=$categoriesIN[] multiple=multiple OPTIONChoose Categories.../option OPTION VALUE=? echo $categoriesIN; ?1 OPTION VALUE=? echo $categoriesIN; ?2 OPTION VALUE=? echo $categoriesIN; ?3 OPTION VALUE=? echo $categoriesIN; ?4 OPTION VALUE=? echo $categoriesIN; ?5 /SELECT ...snip... $sql4 = FOR ( $ii = 0 ; $ii count($categoriesIN) ; $ii++ ) INSERT INTO temp (example) $categoriesIN[$ii] ; $result4 = mysql_query($sql4, $db); ...snip this does not work! The other posts work like a charm... but this... You are confusing the PHP and MySQL. ?php $count = count($categoriesIN); for ($ii = 0; $ii $count; ++$ii) { $sql = INSERT INTO temp (example) VALUES (' . mysql_real_escape_string($categoriesIN[$ii]) . '); $result = mysql_query($sql, $db); } ? MySQL also has an alternative syntax that you can use to do this in a single statement: ?php $count = count($categoriesIN); if ($count 0) { $sql = INSERT INTO temp (example) VALUES ; for ($ii = 0; $ii $count; ++$ii) { if ($ii 0) $sql .= ', '; $sql .= (' . mysql_real_escape_string($categoriesIN[$ii]) . '); } } $result = mysql_query($sql, $db); ? Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] multiple choice dropdown box puzzle
PJ wrote: I think this is a tough one... and way above my head: PLEASE READ ALL OF THE ABOVE TO UNDERSTAND WHAT I AM TRYING TO DO. Having a bit of a rough time figuring out how to formulate php-mysql to insert data into fields using a multiple dropdown box in a form. to post I am using the following: snip... $categoriesIN = $_POST[categoriesIN]; ...snip... select name=$categoriesIN[] multiple=multiple OPTIONChoose Categories.../option OPTION VALUE=? echo $categoriesIN; ?1 OPTION VALUE=? echo $categoriesIN; ?2 OPTION VALUE=? echo $categoriesIN; ?3 OPTION VALUE=? echo $categoriesIN; ?4 OPTION VALUE=? echo $categoriesIN; ?5 /SELECT ...snip... $sql4 = FOR ( $ii = 0 ; $ii count($categoriesIN) ; $ii++ ) INSERT INTO temp (example) $categoriesIN[$ii] ; $result4 = mysql_query($sql4, $db); ...snip this does not work! The other posts work like a charm... but this... I cannot figure out what I should be entering where... I have tried several different configurations, but nothing seems to work... I found this as a model for entering the selections but can't figure out how to modify it for my needs: select name=branch_no[] multiple=multiple size=5 option Choose your location(s) /option option value=31003100/option option value=31053105/option option value=3503 3503/option option value=3504 3504/option /select What I would like to do is something like the following: select name=$categoriesIN[] multiple=multiple OPTIONChoose Categories.../option OPTION VALUE=1History OPTION VALUE=2Temples OPTION VALUE=2Pharaohs and Queens OPTION VALUE=4Cleopatra OPTION VALUE=4Mummies /SELECT and going further, I would like to be able to use a table that actually holds these values to feed them to the code above. I am sure this is possible but it must take some huge knowledge and experience to do it. BUT ... as I look at things, I am wondering if the FOR statement in the above should be used to do several INSERTs, that is, one $sql(number) per selected category... now, would that require many $sqls or many INSERTs within the $sql ? first, I think, $categoriesIN is string, but in the form you made it as an array $categoriesIN[]. I think you have to modify it a little bit, something like {$categoriesIN}.'[]' second, I think the php part FOR ( $ii = 0 ; $ii count($categoriesIN) ; $ii++ ) can't be part of the mysql statement, it should be outside the statement FOR ( $ii = 0 ; $ii count($categoriesIN) ; $ii++ ) { $sql4 = INSERT INTO temp (example) $categoriesIN[$ii] ; $result4 = mysql_query($sql4, $db); } afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ms-word reading from PHP on linux O.S
Srinivasa Rao D wrote: Hi all, * How better, i can read ms-word doc files from PHP on LINUX OS*.On searching I got *catdoc* softaware.By using this i can read word doc data as a text. function catdoc_file($fname) { $ret = exec('catdoc -ab '.escapeshellarg($fname) .' 21'); if (preg_match('/^sh: line 1: catdoc/i',$ret)) { return false; } return trim($ret); } It is working well. *Is there are any other softwares that can fetch text from MS-WORD file?.* I wrote this routine a few months ago. $filename = './lflf.doc'; if ( file_exists($filename) ) { if ( ($fh = fopen($filename, 'r')) !== false ) { $headers = fread($fh, 0xA00); # 1 = (ord(n)*1) ; Document has from 0 to 255 characters $n1 = ( ord($headers[0x21C]) - 1 ); # 1 = ((ord(n)-8)*256) ; Document has from 256 to 63743 characters $n2 = ( ( ord($headers[0x21D]) - 8 ) * 256 ); # 1 = ((ord(n)*256)*256) ; Document has from 63744 to 16775423 characters $n3 = ( ( ord($headers[0x21E]) * 256 ) * 256 ); # 1 = (((ord(n)*256)*256)*256) ; Document has from 16775424 to 4294965504 characters $n4 = ( ( ( ord($headers[0x21F]) * 256 ) * 256 ) * 256 ); # Total length of text in the document $textLength = ($n1 + $n2 + $n3 + $n4); $extracted_plaintext = fread($fh, $textLength); # if you want the plain text with no formatting, do this echo $extracted_plaintext; # if you want to see your paragraphs in a web page, do this echo nl2br($extracted_plaintext); fclose($fh); } } This will grab the plain text out of a word document. Version 97' - 2003' It doesn't work for the newest OpenXML document format. -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RecursiveDirectoryIterator and foreach
I have discovered that when I foreach over a RecursiveDirectoryIterator (see example below) the $item actually turns into a SplFileInfo object. I would expect it to be a RecursiveDirectoryIterator. How do I do a hasChildren() on SplFileInfo? However, if I change it to a non-recursive, DirectoryIterator, $item is what I would expect, DirectoryIterator. I've tested this with 5.2.8 and 5.3b1. I'm guessing this is an issue with my setup as I'm sure I've gotten this to work before... $dir = new RecursiveDirectoryIterator('/path/to/dir'); foreach ($dir as $item) { print get_class($item) . \r\n; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: multiple choice dropdown box puzzle
It's actually a very simple solution, and you should do it all in a single INSERT. Putting INSERTs in a loop will kill your performance when you try to scale. $sql4 = 'INSERT INTO temp (example) VALUES (' . implode('),(', $_POST[categoriesIN]) . ')'; $result4 = mysql_query($sql4, $db); That example does not sanitize the data before inserting. Brent On Mon, Feb 23, 2009 at 10:25 AM, PJ af.gour...@videotron.ca wrote: I think this is a tough one... and way above my head: PLEASE READ ALL OF THE ABOVE TO UNDERSTAND WHAT I AM TRYING TO DO. Having a bit of a rough time figuring out how to formulate php-mysql to insert data into fields using a multiple dropdown box in a form. to post I am using the following: snip... $categoriesIN = $_POST[categoriesIN]; ...snip... select name=$categoriesIN[] multiple=multiple OPTIONChoose Categories.../option OPTION VALUE=? echo $categoriesIN; ?1 OPTION VALUE=? echo $categoriesIN; ?2 OPTION VALUE=? echo $categoriesIN; ?3 OPTION VALUE=? echo $categoriesIN; ?4 OPTION VALUE=? echo $categoriesIN; ?5 /SELECT ...snip... $sql4 = FOR ( $ii = 0 ; $ii count($categoriesIN) ; $ii++ ) INSERT INTO temp (example) $categoriesIN[$ii] ; $result4 = mysql_query($sql4, $db); ...snip this does not work! The other posts work like a charm... but this... I cannot figure out what I should be entering where... I have tried several different configurations, but nothing seems to work... I found this as a model for entering the selections but can't figure out how to modify it for my needs: select name=branch_no[] multiple=multiple size=5 option Choose your location(s) /option option value=31003100/option option value=31053105/option option value=3503 3503/option option value=3504 3504/option /select What I would like to do is something like the following: select name=$categoriesIN[] multiple=multiple OPTIONChoose Categories.../option OPTION VALUE=1History OPTION VALUE=2Temples OPTION VALUE=2Pharaohs and Queens OPTION VALUE=4Cleopatra OPTION VALUE=4Mummies /SELECT and going further, I would like to be able to use a table that actually holds these values to feed them to the code above. I am sure this is possible but it must take some huge knowledge and experience to do it. BUT ... as I look at things, I am wondering if the FOR statement in the above should be used to do several INSERTs, that is, one $sql(number) per selected category... now, would that require many $sqls or many INSERTs within the $sql ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=brentt...@gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RecursiveDirectoryIterator and foreach
Here's a RecursiveDirectoryIterator class I've written and find quite useful: ?php /** * This class encapsulates an iterator that iterates over all the files in a * directory recursively. Only files that don't begin with a '.' are included * in this iteration. This class essentially wraps an SPL DirectoryIterator * object and returns each file in the iteration as an SplFileInfo. * * @author a href=mailto:phi...@lightbox.org;Philip Graham/a */ class Util_RecursiveFileIterator implements Iterator { CONST SHOW_DOT_FILES = true; private $_basePath; private $_curDirIter; private $_dirStack; private $_showDots; /** * Constructor. By default the iteration will skip any files that begin * with a '.' character but this can be changed by passing the class * constant SHOW_DOT_FILES as the second parameter. * * @param string $basePath - The base path of the directory to iterate over * @param boolean $showDots - Whether or not to include files that begin * with a '.' character in the iteration. */ public function __construct($basePath, $showDots = false) { // PREPARE ... THE ... HUMANOID if(!is_dir($basePath)) { $basePath = dirname($basePath); } if(!$basePath) { $basePath = '.'; } // If the given path is relative this function will transform it // into an equivalent path. This call assumes that the relative path // is relative to the file that created this iterator. $this-_basePath = Util_File::getAbsolutePath($basePath, 2); $this-_showDots = $showDots; } /** * Returns the current value of the iteration * * @return FileInfoInfo */ public function current() { return $this-_curDirIter-current(); } /** * Returns the index of the current entry. * * @return string */ public function key() { $curPath = $this-_curDirIter-getPathname(); $relativeToBase = substr($curPath, strlen($this-_basePath)); return $relativeToBase; } /** * Moves the directory iterator to the next element of the iteration. */ public function next() { $this-_curDirIter-next(); $good = false; while(!$good) { if(!$this-_curDirIter-valid()) { if(count($this-_dirStack) == 0) { $good = true; } else { $this-_curDirIter = array_pop($this-_dirStack); } } else if($this-_curDirIter-isDot()) { if(!$this-_showDots) { $this-_curDirIter-next(); } else { $good = true; } } else if(!$this-_showDots substr($this-_curDirIter-getFileName(), 0, 1) == '.') { $this-_curDirIter-next(); } else if($this-_curDirIter-isDir()) { // Create a new iterator for the sub-dir $newIter = new DirectoryIterator( $this-_curDirIter-getPathname()); // Make sure the current iterator is ready to go when it // gets popped off the stack $this-_curDirIter-next(); // Push it... push it real good array_push($this-_dirStack, $this-_curDirIter); // Set the new iterator $this-_curDirIter = $newIter; } else { $good = true; } } } /** * Resets the iterator to first file in the object's base path. */ public function rewind() { $this-_curDirIter = new DirectoryIterator($this-_basePath); $this-_dirStack = array(); if(!$this-_showDots $this-_curDirIter-isDot()) { $this-next(); } } /** * Returns a boolean indicating wether or not there are anymore elements left * in the iteration. */ public function valid() { return $this-_curDirIter-valid(); } } Usage: $dirIter = new Util_RecursiveFileIterator('/path/to/directory'); foreach($dirIter AS $fileName = $fileInfo) { // $fileName is the basename of the file and $fileInfo is a SplFileInfo // for the file } Hope this helps! On February 23, 2009 11:31:04 Ryan Panning wrote: I have discovered that when I foreach over a RecursiveDirectoryIterator (see example below) the $item actually turns into a SplFileInfo object. I would expect it to be a RecursiveDirectoryIterator. How do I do a hasChildren() on SplFileInfo? However, if I change it to a non-recursive, DirectoryIterator, $item is what I would expect, DirectoryIterator. I've tested this with 5.2.8 and 5.3b1. I'm guessing this is an issue with my setup as I'm sure I've gotten this to work before... $dir = new RecursiveDirectoryIterator('/path/to/dir'); foreach ($dir as $item) { print
Re: [PHP] Two troublesome fields (Resolved)
Wow do I feel blind..it was that I missed the ISSET part at the topdidn't have it for those two fieldsDOH!! Thanks all Terion Happy Freecycling Free the List !! www.freecycle.org Over Moderation of Freecycle List Prevents Post Timeliness. Twitter? http://twitter.com/terionmiller Facebook: a href=http://www.facebook.com/people/Terion-Miller/1542024891; title=Terion Miller's Facebook profile target=_TOPimg src= http://badge.facebook.com/badge/1542024891.237.919247960.png; border=0 alt=Terion Miller's Facebook profile/a P. J. O'Rourke - Everybody knows how to raise children, except the people who have them. On Fri, Feb 20, 2009 at 8:51 AM, Sean DeNigris s...@clipperadams.comwrote: *From: *Terion Miller webdev.ter...@gmail.com *Date: *February 19, 2009 5:34:50 PM EST *To: *Bastien Koert phps...@gmail.com *Cc: *PHP General php-general@lists.php.net *Subject: **Re: [PHP] Two troublesome fields* I just tried this and now it's not inserting at all where before everything EXCEPT two fields go in... $sql = INSERT INTO workorders ( CreatedDate, Location, WorkOrderName, AdminID, FormName, Status, Notes) VALUES (; $sql .= Now(), ; $sql .= '. mysql_real_escape_string($Location) .', ; $sql .= '. mysql_real_escape_string($WorkOrderName) .', ; $sql .= '. mysql_real_escape_string($AdminID) .', ; $sql .= '. mysql_real_escape_string(WorkOrder) .', ; $sql .= '. mysql_real_escape_string(New Order) .', ; $sql .= '. mysql_real_escape_string($Notes) .', ; $WorkOrderID = mysql_insert_id(); mysql_query($sql); There's no closing parethesis to VALUES, try... $sql .= '. mysql_real_escape_string($Notes) .'); Sean DeNigris s...@clipperadams.com
Re: [PHP] RecursiveDirectoryIterator and foreach
On Mon, Feb 23, 2009 at 9:31 AM, Ryan Panning rpann...@gmail.com wrote: I have discovered that when I foreach over a RecursiveDirectoryIterator (see example below) the $item actually turns into a SplFileInfo object. I would expect it to be a RecursiveDirectoryIterator. How do I do a hasChildren() on SplFileInfo? However, if I change it to a non-recursive, DirectoryIterator, $item is what I would expect, DirectoryIterator. I've tested this with 5.2.8 and 5.3b1. I'm guessing this is an issue with my setup as I'm sure I've gotten this to work before... $dir = new RecursiveDirectoryIterator('/path/to/dir'); foreach ($dir as $item) { print get_class($item) . \r\n; } if youre trying to do recursive iteration whereby you 'flatten' the tree structure, drop the RecursiveDirectoryIterator into a RecursiveIteratorIterator (its for iterating over RecursiveIterators), then you dont have to bother w/ calling hasChildren() at all. you probly also want to look at the constructor args, since by default, it only returns leaf nodes. $dir = new RecursiveDirectoryIterator('/path/to/dir'); $itt = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST); foreach ($itt as $item) { print get_class($item) . \r\n; } -nathan
Re: [PHP] multiple choice dropdown box puzzle
You're looking for something like: This gets called 10 times from another function, but this is sort of what you're looking for. This gives me a combo-box. function qselect($mysql_link, $i) { $driverquery = select car_no, drv_name from cars order by car_no + 0; $driverresult = mysql_query($driverquery, $mysql_link); print(select name='pick$i'\n); while ($driverrows = mysql_fetch_array($driverresult)) { print( option value = '$driverrows[0]'$driverrows[1]/option\n); } print( /select\n); } HTH Curtis Afan Pasalic wrote: PJ wrote: I think this is a tough one... and way above my head: PLEASE READ ALL OF THE ABOVE TO UNDERSTAND WHAT I AM TRYING TO DO. Having a bit of a rough time figuring out how to formulate php-mysql to insert data into fields using a multiple dropdown box in a form. to post I am using the following: snip... $categoriesIN= $_POST[categoriesIN]; ...snip... select name=$categoriesIN[] multiple=multiple OPTIONChoose Categories.../option OPTION VALUE=? echo $categoriesIN; ?1 OPTION VALUE=? echo $categoriesIN; ?2 OPTION VALUE=? echo $categoriesIN; ?3 OPTION VALUE=? echo $categoriesIN; ?4 OPTION VALUE=? echo $categoriesIN; ?5 /SELECT ...snip... $sql4 = FOR ( $ii = 0 ; $ii count($categoriesIN) ; $ii++ ) INSERT INTO temp (example) $categoriesIN[$ii] ; $result4 = mysql_query($sql4, $db); ...snip this does not work! The other posts work like a charm... but this... I cannot figure out what I should be entering where... I have tried several different configurations, but nothing seems to work... I found this as a model for entering the selections but can't figure out how to modify it for my needs: select name=branch_no[] multiple=multiple size=5 option Choose your location(s) /option option value=31003100/option option value=31053105/option option value=3503 3503/option option value=3504 3504/option /select What I would like to do is something like the following: select name=$categoriesIN[] multiple=multiple OPTIONChoose Categories.../option OPTION VALUE=1History OPTION VALUE=2Temples OPTION VALUE=2Pharaohs and Queens OPTION VALUE=4Cleopatra OPTION VALUE=4Mummies /SELECT and going further, I would like to be able to use a table that actually holds these values to feed them to the code above. I am sure this is possible but it must take some huge knowledge and experience to do it. BUT ... as I look at things, I am wondering if the FOR statement in the above should be used to do several INSERTs, that is, one $sql(number) per selected category... now, would that require many $sqls or many INSERTs within the $sql ? first, I think, $categoriesIN is string, but in the form you made it as an array $categoriesIN[]. I think you have to modify it a little bit, something like {$categoriesIN}.'[]' second, I think the php part FOR ( $ii = 0 ; $ii count($categoriesIN) ; $ii++ ) can't be part of the mysql statement, it should be outside the statement FOR ( $ii = 0 ; $ii count($categoriesIN) ; $ii++ ) { $sql4 = INSERT INTO temp (example) $categoriesIN[$ii] ; $result4 = mysql_query($sql4, $db); } afan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] File Write Operation Slows to a Crawl....
Hi: Newbie here. This is my first attempt at PHP scripting. I'm trying to find an alternative to Lotus Domino's domlog.nsf for logging web transactions. Domino does create an Apache compatible text file of the web transactions, and this is what Im trying to parse. I started off using a code snibbet I found on the web. I modified it a little bit to suit my needs. It was working fine with the small 600k test log file I was using, but since Ive moved to the larger 18Mb production log file heres what happens: Ive modified the code and added an echo statement to echo each loop that gets processed. Initially it starts off very fast but then performance becomes very slow, to a point where I can count each loop as its being processed. Its taking a little over 3 hours to parse the entire file. I figured it was a disk cache thing, so I created a ram drive. This has improved the performance, but is still taking an hour to parse. Here is the PHP script Im using: ?php $ac_arr = file('access_log'); $astring = join(, $ac_arr); $astring = preg_replace(/(\r|\t)/, , $astring); $records = preg_split(/(\n)/, $astring, -1, PREG_SPLIT_NO_EMPTY); $sizerecs = sizeof($records); // now split into records $i = 1; $each_rec = 0; while($i$sizerecs) { $all = $records[$i]; // IP Address ($IP): $IP = substr($all, 0, strpos($all, )); $all = str_replace($IP, , $all); //Remote User ($RU): $string = substr($all, 0, strpos($all, [)); // www.vpcl.on.ca T123 $sstring = substr($string, strpos($string, )+1); $AUstring = substr($sstring, strpos($sstring, )); $RU = preg_replace(/\/, , $AUstring); $RU = trim($RU); $all = str_replace($string, , $all); //Request Time Stamp ($RTS): preg_match(/\[(.+)\]/, $all, $match); $RTS = $match[1]; $all = str_replace( [$RTS] \, , $all); //Http Request Line ($HRL): $string = substr($all, 0, strpos($all, \)+2); $HRL = str_replace(\, , $string); $all = str_replace($string, , $all); //Http Response Status Code (HRSC): $HRSC = trim(substr($all, 0, strpos($all, )+1)); $all = str_replace($HRSC, , $all); //Request Content Length (RCL): $string = substr($all, 0, strpos($all, \)+1); $RCL = trim(str_replace(\, , $string)); $all = str_replace($string, , $all); //Referring URL (RefU): $string = substr($all, 0, strpos($all, \)+3); $RefU = substr($all, 0, strpos($all, \)); $all = str_replace($string, , $all); //User Agent (UA): $string = substr($all, 0, strpos($all, \)+2); $UA = substr($all, 0, strpos($all, \)); $all = str_replace($string, , $all); //Time to Process Request: #$new_format[$each_rec] = $UA\n; $new_format[$each_rec] = $IP\t$RU\t$RTS\t$HRL\t$HRSC\t$RCL\t$RefU\t$UA\t$all\n; $fhandle = fopen(/ramdrive/import_file.txt, w); foreach($new_format as $data) { fputs($fhandle, $data); } fclose($fhandle); // advance to next record echo $i\n; $i = $i + 1; $each_rec++; } ? This is running on a Toshiba Tecra A4 Laptop with FreeBSD 7.0 Release. Plenty of RAM and HDD space. The PHP Version is: PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Feb 11 2009 09:28:47) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies What should I do to get this script to run faster? Any help is appreciated . Regards, Fred Schnittke Powered by Execulink Webmail http://www.execulink.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: RecursiveDirectoryIterator and foreach
Ryan Panning wrote: I have discovered that when I foreach over a RecursiveDirectoryIterator (see example below) the $item actually turns into a SplFileInfo object. I would expect it to be a RecursiveDirectoryIterator. How do I do a hasChildren() on SplFileInfo? However, if I change it to a non-recursive, DirectoryIterator, $item is what I would expect, DirectoryIterator. I've tested this with 5.2.8 and 5.3b1. I'm guessing this is an issue with my setup as I'm sure I've gotten this to work before... $dir = new RecursiveDirectoryIterator('/path/to/dir'); foreach ($dir as $item) { print get_class($item) . \r\n; } Alright, I've found a related PHP bug report. http://bugs.php.net/bug.php?id=44018 It seems that the default behavior is to return a SplFileInfo object. However, if 0 is passed as a flag then a RecursiveDirectoryIterator should be returned. However, I cannot seem to get that to work with 5.2.8. Testing previous versions, this option no longer works as of 5.2.6, but did in 5.2.5. This seems like a bug to me, however that bug was marked as Wont Fix. The default behavior should be RecursiveDirectoryIterator as there is a flag for CURRENT_AS_FILEINFO. Any thoughts on that? @ Marcus, what was the reasoning not to fix this? And why did it break in 5.2.6? In relation, I've found a workaround, use while(). That way I'm always working off of the $dir. I'd rather use foreach though.. $dir = new RecursiveDirectoryIterator('/path/to/dir'); while ($dir-valid()) { print get_class($dir) . \r\n; $dir-next(); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RecursiveDirectoryIterator and foreach
Nathan Nobbe wrote: if youre trying to do recursive iteration whereby you 'flatten' the tree structure, drop the RecursiveDirectoryIterator into a RecursiveIteratorIterator (its for iterating over RecursiveIterators), then you dont have to bother w/ calling hasChildren() at all. you probly also want to look at the constructor args, since by default, it only returns leaf nodes. $dir = new RecursiveDirectoryIterator('/path/to/dir'); $itt = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST); foreach ($itt as $item) { print get_class($item) . \r\n; } -nathan Hi, thanks for the idea. In my case I do not want to flatten the tree. When there is a sub-directory I make a repeat call to the function/method, there-by calling it for each directory. I'd give you more details but I don't think it'd help with this specific issue. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RecursiveDirectoryIterator and foreach
Philip Graham wrote: Here's a RecursiveDirectoryIterator class I've written and find quite useful: ?php /** * This class encapsulates an iterator that iterates over all the files in a * directory recursively. Only files that don't begin with a '.' are included * in this iteration. This class essentially wraps an SPL DirectoryIterator * object and returns each file in the iteration as an SplFileInfo. * * @author a href=mailto:phi...@lightbox.org;Philip Graham/a */ class Util_RecursiveFileIterator implements Iterator { CONST SHOW_DOT_FILES = true; private $_basePath; private $_curDirIter; private $_dirStack; private $_showDots; /** * Constructor. By default the iteration will skip any files that begin * with a '.' character but this can be changed by passing the class * constant SHOW_DOT_FILES as the second parameter. * * @param string $basePath - The base path of the directory to iterate over * @param boolean $showDots - Whether or not to include files that begin * with a '.' character in the iteration. */ public function __construct($basePath, $showDots = false) { // PREPARE ... THE ... HUMANOID if(!is_dir($basePath)) { $basePath = dirname($basePath); } if(!$basePath) { $basePath = '.'; } // If the given path is relative this function will transform it // into an equivalent path. This call assumes that the relative path // is relative to the file that created this iterator. $this-_basePath = Util_File::getAbsolutePath($basePath, 2); $this-_showDots = $showDots; } /** * Returns the current value of the iteration * * @return FileInfoInfo */ public function current() { return $this-_curDirIter-current(); } /** * Returns the index of the current entry. * * @return string */ public function key() { $curPath = $this-_curDirIter-getPathname(); $relativeToBase = substr($curPath, strlen($this-_basePath)); return $relativeToBase; } /** * Moves the directory iterator to the next element of the iteration. */ public function next() { $this-_curDirIter-next(); $good = false; while(!$good) { if(!$this-_curDirIter-valid()) { if(count($this-_dirStack) == 0) { $good = true; } else { $this-_curDirIter = array_pop($this-_dirStack); } } else if($this-_curDirIter-isDot()) { if(!$this-_showDots) { $this-_curDirIter-next(); } else { $good = true; } } else if(!$this-_showDots substr($this-_curDirIter-getFileName(), 0, 1) == '.') { $this-_curDirIter-next(); } else if($this-_curDirIter-isDir()) { // Create a new iterator for the sub-dir $newIter = new DirectoryIterator( $this-_curDirIter-getPathname()); // Make sure the current iterator is ready to go when it // gets popped off the stack $this-_curDirIter-next(); // Push it... push it real good array_push($this-_dirStack, $this-_curDirIter); // Set the new iterator $this-_curDirIter = $newIter; } else { $good = true; } } } /** * Resets the iterator to first file in the object's base path. */ public function rewind() { $this-_curDirIter = new DirectoryIterator($this-_basePath); $this-_dirStack = array(); if(!$this-_showDots $this-_curDirIter-isDot()) { $this-next(); } } /** * Returns a boolean indicating wether or not there are anymore elements left * in the iteration. */ public function valid() { return $this-_curDirIter-valid(); } } Usage: $dirIter = new Util_RecursiveFileIterator('/path/to/directory'); foreach($dirIter AS $fileName = $fileInfo) { // $fileName is the basename of the file and $fileInfo is a SplFileInfo // for the file } Hope this helps! Hi, although I don't think this will work in my situation, there is an interesting piece of code that you have. array_push($this-_dirStack, $this-_curDirIter); Are you able to inject the iterator with more items? I would like to do this with the RecursiveDirectoryIterator where-by I inject fake files into the iterator. Is this what you're doing here? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: multiple choice dropdown box puzzle
Here's my test page and, so far, nothing works... ? session_start();// Include sessions_start() in everything include (db1.php); $thisInterface = addNewBooks; if (!isset($_SESSION[addNewBooks])) { $categoriesIN= ; // Save the input variables in session variables $_SESSION[categoriesIN]= $categoriesIN; // Remember that addNewBooks.php has been entered once $_SESSION[addNewBooks] = 1; } else { $categoriesIN= $_SESSION[categoriesIN]; } ? form method=post action=multiple_category_insert.php select name=?echo $categoriesIN?.'[]' multiple=multiple size=5 option Choose categories... /option option value=1History/option option value=2Temples/option option value=3 Cleopatra/option option value=4 Mummies/option /select br input type=submit name=submit value=submit /form ? $sql4 = 'INSERT INTO test (example) VALUES (' . implode('),(', $_POST[categoriesIN]) . ')'; $result4 = mysql_query($sql4, $db); ? table align=center border=0 cellpadding=3 width=90% tr td align=centerb input class=textbox type=submit name=AddNewBooksRequest value=Insert New Books /b /td /tr /table Brent Baisley wrote: It's actually a very simple solution, and you should do it all in a single INSERT. Putting INSERTs in a loop will kill your performance when you try to scale. $sql4 = 'INSERT INTO temp (example) VALUES (' . implode('),(', $_POST[categoriesIN]) . ')'; $result4 = mysql_query($sql4, $db); That example does not sanitize the data before inserting. Brent On Mon, Feb 23, 2009 at 10:25 AM, PJ af.gour...@videotron.ca wrote: I think this is a tough one... and way above my head: PLEASE READ ALL OF THE ABOVE TO UNDERSTAND WHAT I AM TRYING TO DO. Having a bit of a rough time figuring out how to formulate php-mysql to insert data into fields using a multiple dropdown box in a form. to post I am using the following: snip... $categoriesIN = $_POST[categoriesIN]; ...snip... select name=$categoriesIN[] multiple=multiple OPTIONChoose Categories.../option OPTION VALUE=? echo $categoriesIN; ?1 OPTION VALUE=? echo $categoriesIN; ?2 OPTION VALUE=? echo $categoriesIN; ?3 OPTION VALUE=? echo $categoriesIN; ?4 OPTION VALUE=? echo $categoriesIN; ?5 /SELECT ...snip... $sql4 = FOR ( $ii = 0 ; $ii count($categoriesIN) ; $ii++ ) INSERT INTO temp (example) $categoriesIN[$ii] ; $result4 = mysql_query($sql4, $db); ...snip this does not work! The other posts work like a charm... but this... I cannot figure out what I should be entering where... I have tried several different configurations, but nothing seems to work... I found this as a model for entering the selections but can't figure out how to modify it for my needs: select name=branch_no[] multiple=multiple size=5 option Choose your location(s) /option option value=31003100/option option value=31053105/option option value=3503 3503/option option value=3504 3504/option /select What I would like to do is something like the following: select name=$categoriesIN[] multiple=multiple OPTIONChoose Categories.../option OPTION VALUE=1History OPTION VALUE=2Temples OPTION VALUE=2Pharaohs and Queens OPTION VALUE=4Cleopatra OPTION VALUE=4Mummies /SELECT and going further, I would like to be able to use a table that actually holds these values to feed them to the code above. I am sure this is possible but it must take some huge knowledge and experience to do it. BUT ... as I look at things, I am wondering if the FOR statement in the above should be used to do several INSERTs, that is, one $sql(number) per selected category... now, would that require many $sqls or many INSERTs within the $sql ? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=brentt...@gmail.com -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RecursiveDirectoryIterator and foreach
On February 23, 2009 12:32:26 Ryan Panning wrote: Hi, although I don't think this will work in my situation, there is an interesting piece of code that you have. array_push($this-_dirStack, $this-_curDirIter); Are you able to inject the iterator with more items? I would like to do this with the RecursiveDirectoryIterator where-by I inject fake files into the iterator. Is this what you're doing here? Yes, in essence that is what this is doing but I am not manipulating the DirectoryIterator objects. I am instead using my own structure and logic to do this. Basically I'm using normal (i.e flat) DirectoryIterator objects but when I encounter a sub directory, I instantiate another DirectoryIterator for the sub-directory to continue the iteration. In order to remember where I was once I've finished iterating over the sub-directory the current iterator is pushed onto a stack. Then once the iteration of the sub-directory is finished the iterator for the parent directory is popped off the stack and the iteration over that directory continues from where it was interrupted. Does this explanation satisfy your question? -- Philip Graham Lightbox Technologies Suite 312 240 Catherine St. Ottawa, ON, K2P 2G8 613-686-1661 ext. 102 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PDO buffered query problem
Hi there, I'm having some serious problems with the PHP Data Object functions. I'm trying to loop through a sizeable result set (~60k rows, ~1gig) using a buffered query to avoid fetching the whole set. No matter what I do, the script just hangs on the PDO::query() - it seems the query is running unbuffered (why else would the change in result set size 'fix' the issue?). Here is my code to reproduce the problem: ?php $Database = new PDO( 'mysql:host=localhost;port=3306;dbname=mydatabase', 'root', '', array( PDO::ATTR_ERRMODE = PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY = true ) ); $rQuery = $Database-query('SELECT id FROM mytable'); // This is never reached because the result set is too large echo 'Made it through.'; foreach($rQuery as $aRow) { print_r($aRow); } ? If I limit the query with some reasonable number, it works fine: $rQuery = $Database-query('SELECT id FROM mytable LIMIT 10'); I have tried playing with PDO::MYSQL_ATTR_MAX_BUFFER_SIZE and using the PDO::prepare() and PDO::execute() as well (though there are no parameters in the above query), both to no avail. Any help would be appreciated, Stewart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] help installing phpDocumentor
I have tried to install phpDocumentor, but am having problems getting it to run. Finding install directions has so far eluded me. Are there any installation instructions for this? Jim White -- James (Jim) B. White tel: (919)-380-9615 homepage: http://jimserver.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: multiple choice dropdown box puzzle
From: PJ Here's my test page and, so far, nothing works... Please expound on nothing works What do you see in the browser? What do you see in the server logs? ? I strongly recommend changing all of these to ?php per the XHTML specs. That will reduce the ambiguity and possibly prevent errors like the next one. select name=?echo $categoriesIN?.'[]' multiple=multiple size=5 You at least need a space between ? and echo, otherwise the server is trying to parse ?echo as a single token, and that is probably undefined. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help installing phpDocumentor
jim white wrote: I have tried to install phpDocumentor, but am having problems getting it to run. Finding install directions has so far eluded me. Are there any installation instructions for this? Jim White searching google for install phpDocumentor first result is this http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.quickstart.pkg.html Is this what you are looking for? -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RecursiveDirectoryIterator and foreach
On Mon, Feb 23, 2009 at 10:27 AM, Ryan Panning rpann...@gmail.com wrote: Nathan Nobbe wrote: if youre trying to do recursive iteration whereby you 'flatten' the tree structure, drop the RecursiveDirectoryIterator into a RecursiveIteratorIterator (its for iterating over RecursiveIterators), then you dont have to bother w/ calling hasChildren() at all. you probly also want to look at the constructor args, since by default, it only returns leaf nodes. $dir = new RecursiveDirectoryIterator('/path/to/dir'); $itt = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST); foreach ($itt as $item) { print get_class($item) . \r\n; } -nathan im not sure i fully understand the problem, but from the sound of it, as a work-around, why not something like this, $dirIt = new RecursiveDirectoryIterator($path); foreach($dirIt as $item) { if($item-isDir()) { $subdir = new RecursiveDirectoryIterator($item); // now you have the RecursiveDirectoryIterator you wanted ?? } } -nathan
Re: [PHP] help installing phpDocumentor
Jim Lucas wrote: jim white wrote: I have tried to install phpDocumentor, but am having problems getting it to run. Finding install directions has so far eluded me. Are there any installation instructions for this? Jim White searching google for install phpDocumentor first result is this http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.quickstart.pkg.html Is this what you are looking for? No, I already found that. I have installed it according to the instructions. PEAR didn't work at all, and install using tar file only partly works. -- James (Jim) B. White tel: (919)-380-9615 homepage: http://jimserver.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help installing phpDocumentor
jim white wrote: Jim Lucas wrote: jim white wrote: I have tried to install phpDocumentor, but am having problems getting it to run. Finding install directions has so far eluded me. Are there any installation instructions for this? Jim White searching google for install phpDocumentor first result is this http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.quickstart.pkg.html Is this what you are looking for? No, I already found that. I have installed it according to the instructions. PEAR didn't work at all, and install using tar file only partly works. When you say PEAR didn't work. What exactly do you mean. If you received an error, what was it? What exactly only partly worked with the tar installer? -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help installing phpDocumentor
Jim Lucas wrote: jim white wrote: Jim Lucas wrote: jim white wrote: I have tried to install phpDocumentor, but am having problems getting it to run. Finding install directions has so far eluded me. Are there any installation instructions for this? Jim White searching google for install phpDocumentor first result is this http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.quickstart.pkg.html Is this what you are looking for? No, I already found that. I have installed it according to the instructions. PEAR didn't work at all, and install using tar file only partly works. When you say PEAR didn't work. What exactly do you mean. If you received an error, what was it? What exactly only partly worked with the tar installer? It seems part of my problem, at least with the tar install, was not setting my directory permissions so it could write the files. PEAR I will skip since I almost have it working using the tar file. I have tried creating docs with HTML:Smarty:default which works, but for HTML:frames:default at the file level I get *Parse error*: syntax error, unexpected T_STRING. Also, if I want to download the other formats, where do you install them? Jim -- James (Jim) B. White tel: (919)-380-9615 homepage: http://jimserver.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: multiple choice dropdown box puzzle
Bob McConnell wrote: From: PJ Here's my test page and, so far, nothing works... Please expound on nothing works What do you see in the browser? What do you see in the server logs? ? I strongly recommend changing all of these to ?php per the XHTML specs. That will reduce the ambiguity and possibly prevent errors like the next one. select name=?echo $categoriesIN?.'[]' multiple=multiple size=5 You at least need a space between ? and echo, otherwise the server is trying to parse ?echo as a single token, and that is probably undefined. Bob McConnell And I'm sure you don't want: name=?echo $categoriesIN?.'[]' Maybe: name=categoriesIN[] -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: File Write Operation Slows to a Crawl....
fschnit...@execulink.com wrote: Hi: Newbie here. This is my first attempt at PHP scripting. I'm trying to find an alternative to Lotus Domino's domlog.nsf for logging web transactions. Domino does create an Apache compatible text file of the web transactions, and this is what I’m trying to parse. I started off using a code snibbet I found on the web. I modified it a little bit to suit my needs. It was working fine with the small 600k test log file I was using, but since I’ve moved to the larger 18Mb production log file here’s what happens: I’ve modified the code and added an echo statement to echo each loop that gets processed. Initially it starts off very fast but then performance becomes very slow, to a point where I can count each loop as it’s being processed. It’s taking a little over 3 hours to parse the entire file. I figured it was a disk cache thing, so I created a ram drive. This has improved the performance, but is still taking an hour to parse. Here is the PHP script I’m using: ?php Why read in an array and then implode it to a string, then split it into an array? Just use file_get_contents() and split it or use file() and then do your preg_replace(/(\r|\t)/, on the array). $ac_arr = file('access_log'); $astring = join(, $ac_arr); $astring = preg_replace(/(\r|\t)/, , $astring); $records = preg_split(/(\n)/, $astring, -1, PREG_SPLIT_NO_EMPTY); $sizerecs = sizeof($records); // now split into records $i = 1; $each_rec = 0; Why not foreach($records as $all) ? while($i$sizerecs) { $all = $records[$i]; All of these $all = str_replace() and othe str_replace() are probably killing you. Rethink a way where you extract the data instead of finding it and then replacing it. // IP Address ($IP): $IP = substr($all, 0, strpos($all, )); $all = str_replace($IP, , $all); //Remote User ($RU): $string = substr($all, 0, strpos($all, [)); // www.vpcl.on.ca T123 $sstring = substr($string, strpos($string, )+1); $AUstring = substr($sstring, strpos($sstring, )); $RU = preg_replace(/\/, , $AUstring); $RU = trim($RU); $all = str_replace($string, , $all); //Request Time Stamp ($RTS): preg_match(/\[(.+)\]/, $all, $match); $RTS = $match[1]; $all = str_replace( [$RTS] \, , $all); //Http Request Line ($HRL): $string = substr($all, 0, strpos($all, \)+2); $HRL = str_replace(\, , $string); $all = str_replace($string, , $all); //Http Response Status Code (HRSC): $HRSC = trim(substr($all, 0, strpos($all, )+1)); $all = str_replace($HRSC, , $all); //Request Content Length (RCL): $string = substr($all, 0, strpos($all, \)+1); $RCL = trim(str_replace(\, , $string)); $all = str_replace($string, , $all); //Referring URL (RefU): $string = substr($all, 0, strpos($all, \)+3); $RefU = substr($all, 0, strpos($all, \)); $all = str_replace($string, , $all); //User Agent (UA): $string = substr($all, 0, strpos($all, \)+2); $UA = substr($all, 0, strpos($all, \)); $all = str_replace($string, , $all); //Time to Process Request: #$new_format[$each_rec] = $UA\n; $new_format[$each_rec] = $IP\t$RU\t$RTS\t$HRL\t$HRSC\t$RCL\t$RefU\t$UA\t$all\n; Each time through the above loop you add a $new_format[$each_rec] and then here you are looping through each one of those. I think if you just move this to the end it will make a drastic improvement. $fhandle = fopen(/ramdrive/import_file.txt, w); foreach($new_format as $data) { fputs($fhandle, $data); } fclose($fhandle); // advance to next record echo $i\n; $i = $i + 1; $each_rec++; } $fhandle = fopen(/ramdrive/import_file.txt, w); foreach($new_format as $data) { fputs($fhandle, $data); } fclose($fhandle); ? This is running on a Toshiba Tecra A4 Laptop with FreeBSD 7.0 Release. Plenty of RAM and HDD space. The PHP Version is: PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Feb 11 2009 09:28:47) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies What should I do to get this script to run faster? Any help is appreciated…. Regards, Fred Schnittke Powered by Execulink Webmail http://www.execulink.com/ -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help installing phpDocumentor
Back on the list... jim white wrote: Jim Lucas wrote: jim white wrote: Jim Lucas wrote: jim white wrote: I have tried to install phpDocumentor, but am having problems getting it to run. Finding install directions has so far eluded me. Are there any installation instructions for this? Jim White searching google for install phpDocumentor first result is this http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.quickstart.pkg.html Is this what you are looking for? No, I already found that. I have installed it according to the instructions. PEAR didn't work at all, and install using tar file only partly works. When you say PEAR didn't work. What exactly do you mean. If you received an error, what was it? What exactly only partly worked with the tar installer? Here is my problem. ?xml version=1.0 encoding=iso-8859-1? Need to look into turning this off or setting my web server to parse it correctly. Jim Best bet would be to tell your system to not use short tags. That is where your parse error is coming from. Or, assuming that the above line is in an included file, change it to ? echo '?xml version=1.0 encoding=iso-8859-1?'; ? or something similar But, if it were me, I would disabled short tags. I may be wrong, but I heard short tags were going the way of the Dodo bird as of PHP6. -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File Write Operation Slows to a Crawl....
On Mon, Feb 23, 2009 at 11:59:20AM -0500, fschnit...@execulink.com wrote: Hi: Newbie here. This is my first attempt at PHP scripting. I'm trying to find an alternative to Lotus Domino's domlog.nsf for logging web transactions. Domino does create an Apache compatible text file of the web transactions, and this is what Im trying to parse. I started off using a code snibbet I found on the web. I modified it a little bit to suit my needs. It was working fine with the small 600k test log file I was using, but since Ive moved to the larger 18Mb production log file heres what happens: Ive modified the code and added an echo statement to echo each loop that gets processed. Initially it starts off very fast but then performance becomes very slow, to a point where I can count each loop as its being processed. Its taking a little over 3 hours to parse the entire file. I figured it was a disk cache thing, so I created a ram drive. This has improved the performance, but is still taking an hour to parse. Here is the PHP script Im using: ?php $ac_arr = file('access_log'); $astring = join(, $ac_arr); First, don't use file() (which reads a file into an array of strings), and then join() (which makes them into a single string). Use file_get_contents(), which does what you want all in one step. The result is a single string. $astring = preg_replace(/(\r|\t)/, , $astring); Use two calls to str_replace() for the above. It's likely faster because it doesn't involve regular expressions iterated over an 18M file. $records = preg_split(/(\n)/, $astring, -1, PREG_SPLIT_NO_EMPTY); It looks like you're trying to split the string at newlines. So you end up with an array of strings again. If that's the case, just stick with the file() call earlier, and then remove the \r's and \t's. $sizerecs = sizeof($records); // now split into records $i = 1; $each_rec = 0; while($i$sizerecs) { $all = $records[$i]; // IP Address ($IP): $IP = substr($all, 0, strpos($all, )); $all = str_replace($IP, , $all); //Remote User ($RU): $string = substr($all, 0, strpos($all, [)); // www.vpcl.on.ca T123 $sstring = substr($string, strpos($string, )+1); $AUstring = substr($sstring, strpos($sstring, )); $RU = preg_replace(/\/, , $AUstring); $RU = trim($RU); $all = str_replace($string, , $all); //Request Time Stamp ($RTS): preg_match(/\[(.+)\]/, $all, $match); $RTS = $match[1]; $all = str_replace( [$RTS] \, , $all); //Http Request Line ($HRL): $string = substr($all, 0, strpos($all, \)+2); $HRL = str_replace(\, , $string); $all = str_replace($string, , $all); //Http Response Status Code (HRSC): $HRSC = trim(substr($all, 0, strpos($all, )+1)); $all = str_replace($HRSC, , $all); //Request Content Length (RCL): $string = substr($all, 0, strpos($all, \)+1); $RCL = trim(str_replace(\, , $string)); $all = str_replace($string, , $all); //Referring URL (RefU): $string = substr($all, 0, strpos($all, \)+3); $RefU = substr($all, 0, strpos($all, \)); $all = str_replace($string, , $all); //User Agent (UA): $string = substr($all, 0, strpos($all, \)+2); $UA = substr($all, 0, strpos($all, \)); $all = str_replace($string, , $all); //Time to Process Request: #$new_format[$each_rec] = $UA\n; $new_format[$each_rec] = $IP\t$RU\t$RTS\t$HRL\t$HRSC\t$RCL\t$RefU\t$UA\t$all\n; I would do various cleanups in the above code, but the following code disturbs me. If I'm not misreading, you're reopening this output file with every iteration through your file. That is, for each line you process, you're opening and writing one line to the file, then closing the file again. If you're relatively certain no one else will be writing to this file, simply open it once before your while() loop, and write a single line to it at this point. Also, you're using a foreach loop here, but if I'm reading this properly, you only have one record you're writing, so there's no need for a loop. In fact, you're also storing the results in a progressively larger and larger array ($new_format). Since you're not using this array for any other purpose, there's no point in using an array. Just use a string to store it, and then write it back out. So instead of what you're doing below, and considering that $new_format will be a string instead of an array, just do: fputs($fhandle, $new_format); Close the file after the end of your loop. I must be reading this wrong, because it looks to me like you're actually writing n+1 lines to the file for each iteration (n). I don't think that's what you had in mind. That's why you don't need a loop here. If what I'm saying isn't clear, consider this: The way this is written, $new_format is an array that grows by one value (string) each iteration. But with each iteration, you're writing out the *whole* array to the file. The first time through, you write one line. The second time through, you're writing the first line again, and then the second. Third time through,
[PHP] Having Trouble With Session Variable in Query Statement
Hi folks, I'm trying to make an update query with a session variable... It creates this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in ... Q: the session var shows ok on the page : ID ?php echo $_SESSION['now_poid']; ? - so how do I fix the error? == ?php require_once('../Connections/dblink.php'); if(!session_id()) session_start(); $amt = 18; $id1 = 8; $_SESSION['thisid']=8; $id2 = $_SESSION['thisid'] ; //these 3 work $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=8; $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=$id1; $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=$id2; // uses $_SESSION['thisid'] //but this does not.. $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=$_SESSION['thisid']; Q: How can I fix it? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Having Trouble With Session Variable in Query Statement
On Mon, Feb 23, 2009 at 12:34:58PM -0800, revDAVE wrote: Hi folks, I'm trying to make an update query with a session variable... It creates this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in ... Q: the session var shows ok on the page : ID ?php echo $_SESSION['now_poid']; ? - so how do I fix the error? == ?php require_once('../Connections/dblink.php'); if(!session_id()) session_start(); $amt = 18; $id1 = 8; $_SESSION['thisid']=8; $id2 = $_SESSION['thisid'] ; //these 3 work $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=8; $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=$id1; $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=$id2; // uses $_SESSION['thisid'] //but this does not.. $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=$_SESSION['thisid']; Don't single quote values inside array brackets when the whole expression is in double quotes. You've got: ... $_SESSION['thisid']; Do this instead: ... $_SESSION[thisid]; Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Having Trouble With Session Variable in Query Statement
On February 23, 2009 15:34:58 revDAVE wrote: Hi folks, //but this does not.. $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=$_SESSION['thisid']; Q: How can I fix it? try : $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id={$_SESSION['thisid']}; or even better: $updateSQL =UPDATE `mytable` SET thetotal=.mysql_real_escape_string($amt). WHERE id=.mysql_real_escape_string($_SESSION['thisid']); substituting mysql_real_escape_string with the escape function for your database. -- Philip Graham Lightbox Technologies Suite 312 240 Catherine St. Ottawa, ON, K2P 2G8 613-686-1661 ext. 102 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Having Trouble With Session Variable in Query Statement
On 2/23/2009 12:44 PM, Paul M Foster pa...@quillandmouse.com wrote: Don't single quote values inside array brackets when the whole expression is in double quotes. You've got: ... $_SESSION['thisid']; Do this instead: ... $_SESSION[thisid]; AHA - thanks much - that worked! -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Having Trouble With Session Variable in Query Statement
Paul M Foster wrote: On Mon, Feb 23, 2009 at 12:34:58PM -0800, revDAVE wrote: Hi folks, I'm trying to make an update query with a session variable... It creates this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in ... Q: the session var shows ok on the page : ID ?php echo $_SESSION['now_poid']; ? - so how do I fix the error? == ?php require_once('../Connections/dblink.php'); if(!session_id()) session_start(); $amt = 18; $id1 = 8; $_SESSION['thisid']=8; $id2 = $_SESSION['thisid'] ; //these 3 work $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=8; $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=$id1; $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=$id2; // uses $_SESSION['thisid'] //but this does not.. $updateSQL =UPDATE `mytable` SET thetotal=$amt WHERE id=$_SESSION['thisid']; Don't single quote values inside array brackets when the whole expression is in double quotes. You've got: ... $_SESSION['thisid']; Do this instead: ... $_SESSION[thisid]; Paul Better off doing this so you don't get into the habit of not using quotes around array params: ... {$_SESSION['thisid']}; See this: http://us2.php.net/manual/en/language.types.string.php#language.types.string.parsing Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com
Re: [PHP] File Write Operation Slows to a Crawl....
Thanks Paul and Shawn: I can't answer the Why's in your posts, as this is literally my first attempt at PHP, but I will investigate your response and refine my code accordingly. What I did find is that by replacing the following code: $fhandle = fopen(/ramdrive/import_file.txt, w); foreach($new_format as $data) { fputs($fhandle, $data); } fclose($fhandle); with this code: $fp = fopen('data.txt', 'a'); fwrite($fp, $new_format[$each_rec]); fclose($fp); The parsing finished literally, within seconds. I don't have to worry about anyone else opening this file, so I think this should work ok. Thanks for your help Fred Schnittke Powered by Execulink Webmail http://www.execulink.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: File Write Operation Slows to a Crawl....
Shawn McKenzie wrote: fschnit...@execulink.com wrote: Hi: Newbie here. This is my first attempt at PHP scripting. I'm trying to find an alternative to Lotus Domino's domlog.nsf for logging web transactions. Domino does create an Apache compatible text file of the web transactions, and this is what I’m trying to parse. I started off using a code snibbet I found on the web. I modified it a little bit to suit my needs. It was working fine with the small 600k test log file I was using, but since I’ve moved to the larger 18Mb production log file here’s what happens: I’ve modified the code and added an echo statement to echo each loop that gets processed. Initially it starts off very fast but then performance becomes very slow, to a point where I can count each loop as it’s being processed. It’s taking a little over 3 hours to parse the entire file. I figured it was a disk cache thing, so I created a ram drive. This has improved the performance, but is still taking an hour to parse. Here is the PHP script I’m using: ?php Why read in an array and then implode it to a string, then split it into an array? Just use file_get_contents() and split it or use file() and then do your preg_replace(/(\r|\t)/, on the array). $ac_arr = file('access_log'); $astring = join(, $ac_arr); $astring = preg_replace(/(\r|\t)/, , $astring); $records = preg_split(/(\n)/, $astring, -1, PREG_SPLIT_NO_EMPTY); $sizerecs = sizeof($records); // now split into records $i = 1; $each_rec = 0; Why not foreach($records as $all) ? while($i$sizerecs) { $all = $records[$i]; All of these $all = str_replace() and othe str_replace() are probably killing you. Rethink a way where you extract the data instead of finding it and then replacing it. // IP Address ($IP): $IP = substr($all, 0, strpos($all, )); $all = str_replace($IP, , $all); //Remote User ($RU): $string = substr($all, 0, strpos($all, [)); // www.vpcl.on.ca T123 $sstring = substr($string, strpos($string, )+1); $AUstring = substr($sstring, strpos($sstring, )); $RU = preg_replace(/\/, , $AUstring); $RU = trim($RU); $all = str_replace($string, , $all); //Request Time Stamp ($RTS): preg_match(/\[(.+)\]/, $all, $match); $RTS = $match[1]; $all = str_replace( [$RTS] \, , $all); //Http Request Line ($HRL): $string = substr($all, 0, strpos($all, \)+2); $HRL = str_replace(\, , $string); $all = str_replace($string, , $all); //Http Response Status Code (HRSC): $HRSC = trim(substr($all, 0, strpos($all, )+1)); $all = str_replace($HRSC, , $all); //Request Content Length (RCL): $string = substr($all, 0, strpos($all, \)+1); $RCL = trim(str_replace(\, , $string)); $all = str_replace($string, , $all); //Referring URL (RefU): $string = substr($all, 0, strpos($all, \)+3); $RefU = substr($all, 0, strpos($all, \)); $all = str_replace($string, , $all); //User Agent (UA): $string = substr($all, 0, strpos($all, \)+2); $UA = substr($all, 0, strpos($all, \)); $all = str_replace($string, , $all); //Time to Process Request: #$new_format[$each_rec] = $UA\n; $new_format[$each_rec] = $IP\t$RU\t$RTS\t$HRL\t$HRSC\t$RCL\t$RefU\t$UA\t$all\n; Each time through the above loop you add a $new_format[$each_rec] and then here you are looping through each one of those. I think if you just move this to the end it will make a drastic improvement. $fhandle = fopen(/ramdrive/import_file.txt, w); foreach($new_format as $data) { fputs($fhandle, $data); } fclose($fhandle); // advance to next record echo $i\n; $i = $i + 1; $each_rec++; } $fhandle = fopen(/ramdrive/import_file.txt, w); foreach($new_format as $data) { fputs($fhandle, $data); } fclose($fhandle); ? This is running on a Toshiba Tecra A4 Laptop with FreeBSD 7.0 Release. Plenty of RAM and HDD space. The PHP Version is: PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Feb 11 2009 09:28:47) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies What should I do to get this script to run faster? Any help is appreciated…. Regards, Fred Schnittke Powered by Execulink Webmail http://www.execulink.com/ I see that Paul replied and we say the same things, so here are the two best approaches to speed it up ignoring all the str_replaces(), etc. that need to be gotten rid of: // option 1 - i would assume this to be the most efficient / fastest $ac_arr = file('access_log'); $records = preg_replace(/(\r|\t)/, , $ac_arr); $fhandle = fopen(/ramdrive/import_file.txt, w); foreach($records as $all) { // manipulate your data // if you actually need the array then assign it here // $new_format[] = // $IP\t$RU\t$RTS\t$HRL\t$HRSC\t$RCL\t$RefU\t$UA\t$all\n // else just do this fputs($fhandle, $IP\t$RU\t$RTS\t$HRL\t$HRSC\t$RCL\t$RefU\t$UA\t$all\n); } fclose($fhandle); // option 2 - if you don't need the
Re: [PHP] File Write Operation Slows to a Crawl....
fschnit...@execulink.com wrote: Thanks Paul and Shawn: I can't answer the Why's in your posts, as this is literally my first attempt at PHP, but I will investigate your response and refine my code accordingly. What I did find is that by replacing the following code: $fhandle = fopen(/ramdrive/import_file.txt, w); foreach($new_format as $data) { fputs($fhandle, $data); } fclose($fhandle); with this code: $fp = fopen('data.txt', 'a'); fwrite($fp, $new_format[$each_rec]); fclose($fp); The parsing finished literally, within seconds. I don't have to worry about anyone else opening this file, so I think this should work ok. Thanks for your help Fred Schnittke Powered by Execulink Webmail http://www.execulink.com/ Good job! I posted a minute ago with 2 options, but for your fix I would recommend the following: // move this before your while() $fp = fopen('data.txt', 'w'); //notice the 'w' now // move this after the } that ends your while fclose($fp); Should save even more time because you're not opening and closing the file each time through the while(). -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] File Write Operation Slows to a Crawl....
Hi Shawn: Yes, good idea, I agree Thanks Fred fschnit...@execulink.com wrote: Thanks Paul and Shawn: I can't answer the Why's in your posts, as this is literally my first attempt at PHP, but I will investigate your response and refine my code accordingly. What I did find is that by replacing the following code: $fhandle = fopen(/ramdrive/import_file.txt, w); foreach($new_format as $data) { fputs($fhandle, $data); } fclose($fhandle); with this code: $fp = fopen('data.txt', 'a'); fwrite($fp, $new_format[$each_rec]); fclose($fp); The parsing finished literally, within seconds. I don't have to worry about anyone else opening this file, so I think this should work ok. Thanks for your help Fred Schnittke Powered by Execulink Webmail http://www.execulink.com/ Good job! I posted a minute ago with 2 options, but for your fix I would recommend the following: // move this before your while() $fp = fopen('data.txt', 'w'); //notice the 'w' now // move this after the } that ends your while fclose($fp); Should save even more time because you're not opening and closing the file each time through the while(). -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Powered by Execulink Webmail http://www.execulink.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help installing phpDocumentor
Jim Lucas wrote: Back on the list... jim white wrote: Jim Lucas wrote: jim white wrote: Jim Lucas wrote: jim white wrote: I have tried to install phpDocumentor, but am having problems getting it to run. Finding install directions has so far eluded me. Are there any installation instructions for this? Jim White searching google for install phpDocumentor first result is this http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.quickstart.pkg.html Is this what you are looking for? No, I already found that. I have installed it according to the instructions. PEAR didn't work at all, and install using tar file only partly works. When you say PEAR didn't work. What exactly do you mean. If you received an error, what was it? What exactly only partly worked with the tar installer? Here is my problem. ?xml version=1.0 encoding=iso-8859-1? Need to look into turning this off or setting my web server to parse it correctly. Jim Best bet would be to tell your system to not use short tags. That is where your parse error is coming from. Or, assuming that the above line is in an included file, change it to ? echo '?xml version=1.0 encoding=iso-8859-1?'; ? or something similar But, if it were me, I would disabled short tags. I may be wrong, but I heard short tags were going the way of the Dodo bird as of PHP6. Thanks, all looks good now! Jim -- James (Jim) B. White tel: (919)-380-9615 homepage: http://jimserver.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PDO buffered query problem
Stewart Duncan wrote: Hi there, I'm having some serious problems with the PHP Data Object functions. I'm trying to loop through a sizeable result set (~60k rows, ~1gig) using a buffered query to avoid fetching the whole set. No matter what I do, the script just hangs on the PDO::query() - it seems the query is running unbuffered (why else would the change in result set size 'fix' the issue?). Here is my code to reproduce the problem: ?php $Database = new PDO( 'mysql:host=localhost;port=3306;dbname=mydatabase', 'root', '', array( PDO::ATTR_ERRMODE = PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY = true ) ); Don't you want it the other way around? You want it unbuffered so it doesn't get retrieved in mysql, send the whole result set to php then you can use it. You want to start using it immediately - so make it unbuffered. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Why PHP won
http://startuplessonslearned.blogspot.com/2009/01/why-php-won.html
Re: [PHP] Re: Securing web services
Le dimanche 22 février 2009 à 21:29 +, Nathan Rixham a écrit : Yannick Warnier wrote: Hi there, Another Web Service related question. Obviously, Google gives me enough hints to find *many* documents on the topic (searching for securing web services), but I am developing open-source soft and I'd like to secure my web services to the maximum without forcing the user to use HTTPS/SSL (the generation of buying of a certificate is not what our lambda users can do). Yanick, I'm hoping to save you some time here; Web Services are very poorly implemented in PHP (and that sentence is the reason I'm emailing you off-list). Nevermind :-) Everything you need is catered for in SOAP and by using the WS-xxx extensions which are common place in the Java and .net world (infact most languages) - thankfully those who are fortunate enough to know can do this in PHP as well and consume all manner of web services, as well as generate them. You need WSO2 (oxygen) - specifically WSO2 WSF/PHP; it's the finest web service library for all languages and has a massive community behind it. http://wso2.org/projects/wsf/php docs: http://wso2.org/project/wsf/php/2.0.0/docs/api.html The license is Apache 2, which doesn't really match my GPLv2 (or superior) license. Does anyone know how one deals with this kind of headache? If my software is GPLv2 or superior, does it means that if I include a library that is only compatible with GPLv3 I have to restrict my soft to GPLv3? (and not v2 anymore) Apart from that, from a quick view through the code, I didn't really find something better than NuSOAP setCredentials in the list of available functions, but I suppose this should be an off-list topic now... Yannick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] optimizing space for array of booleans
you should not worry about optimizing boolean values unless you would store them in database. I DO need to store them in a database, that's why I'm asking. I won't care if I only use PHP, since it won't keep my data in memory for a long time. anyways, use bitwise operators I think I've stated that I don't want to use bitwise operations. It's OK for small sets, but not for a set with about 200 elements. Anyway, I found bitset library in PECL, but I found no documentation at all. -- View this message in context: http://www.nabble.com/optimizing-space-for-array-of-booleans-tp22159131p22174206.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: multiple choice dropdown box puzzle
Brent Baisley wrote: It's actually a very simple solution, and you should do it all in a single INSERT. Putting INSERTs in a loop will kill your performance when you try to scale. $sql4 = 'INSERT INTO test (example) VALUES (' . implode('),(', $_POST[categoriesIN]) . ')'; $result4 = mysql_query($sql4, $db); Please explain this... I do not understand how the implode is being used here. As I understand it, the above code would aoutput or rather INSERT all the choicees into one field as choice numbers separated by a , (like 1, 3, 4) or what? I suppose I could use that but I'm not sure if this is the way to go. I understand the performance problem and would like to keep it simple. That example does not sanitize the data before inserting. I know, but I am just testing locally for now. Will sanitize later. Brent Here is my test page: Questions below that. html head titletest form/title /head body /body ? session_start();// Include sessions_start() in everything include (db1.php); $thisInterface = addNewBooks; if (!isset($_SESSION[addNewBooks])) { $categoriesIN= ; // Save the input variables in session variables $_SESSION[categoriesIN]= $categoriesIN; // Remember that addNewBooks.php has been entered once $_SESSION[addNewBooks] = 1; } else {$categoriesIN= $_SESSION[categoriesIN]; } if (isset($_REQUEST[AddNewBooksRequest])) $categoriesIN= $_POST[categoriesIN]; ? form method=post action=multiple_category_insert.php select name=$categoriesIN[] multiple size=5 option Choose categories... /option option value=1History/option option value=2Temples/option option value=3 Cleopatra/option option value=4 Mummies/option /select input type=submit name=submit value=submit /form ? $sql4 = INSERT INTO test (example) VALUES (' . implode('),(', $_POST[$categoriesIN]) . '); $result4 = mysql_query($sql4, $db); ? table align=center border=0 cellpadding=3 width=90% tr td align=centerb input class=textbox type=submit name=AddNewBooksRequest value=Insert New Books /b /td /tr /table /html == Question 1. What should be entered into the name= something to make it work? Question 2. How should the $sql4 = INSERT.. be completed? I know the code above is not working but I can't figure out what's wrong. TIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP - user profile page with pic
--- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com -- my level of coding is basic. out of the box is fine as long as it is a good one. I do know how to connect to database pull and display records as well as set up login. But I guess I have to create a session so that when a user logs in only his/her information is shown correct? Yes, and it would be better for you to have an in depth look into the open source projects found. Get to analyse them. So, you'll get familiarized with the advanced well known methods. Learning from them you will be able to create something better and not reinventing the wheels. Lenin -Jeff The question can be equally rephrased as How an Atom bom/Spaceship be created? Answer depends on the level of knowledge you have on coding / developing sites. Woud you be using any framework? or would you use any readymade CMS? Or write everything from scratch? Question can also be generalized further like would php be your developing language? Or you'd develop your own new language out of the box. :) --- Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get a Free CD of Ubuntu mailed to your door without any cost. Visit : www.ubuntu.com -- Any ideas or tutorials on how to build a user profile page sort of like facebook? -Jeff hi, i would recommend Joomla or Wordpress both have extensions for user maintained profiles with pictures. Virgil http://www.jampmark.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] adding whitespace to a timestamp
Maybe the issue is that you are displaying the output in a browser and spaces are not shown. Try puttung nbsp; instead of a literal space. Tim-Hinnerk Heuer http://www.ihostnz.com Henny Youngman - When I told my doctor I couldn't afford an operation, he offered to touch-up my X-rays. 2009/2/24 Andrew Ballard aball...@gmail.com On Sat, Feb 21, 2009 at 1:28 PM, Eric Sherman copyedit...@gmail.com wrote: I hoping to add a space between the date and the time in this: $thedate = date('M jS g:i A', $postTIME); i.e, between* jS* and *g:i* I've looked around but can't find anything. Thanks Eric Sherman Multi Media Information You can put spaces anywhere in that string you want them. What problem are you having? ?php $thedate = date(' M j Sg : i A ', $postTIME); ? Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Having trouble with a multidimensional array menu - new and improved
Okay, I scrapped my multi-array version and have come up with what seems to be a cleaner recursive object way of doing this. The last bit of help I need is in the expandSelectedMenu() part. I need a way to store all the parent nodes above, then traverse them and set their CSS class accordingly as per the comment in the code. //FIXME: so the tricky part is to expand all the directories in the path to $currentMenuItem // we should traverse the -parent maybe?? and set all // ul class=navTree toggleClosed goes to document.getElementById($id).className = navTree; // and (while not required it seems, but is good form) // li id=users class=directory collapsed goes to document.getElementById($id).className = directory; // using the $id = str_replace(array(' ','\ \','-'),'',strtolower($value-menu)); I've tried to do some $value-parent = $parent; but when I var_dump() I start seeing all these *RECURSION* sections. It seems there should be a nicer way to store the 'root node' so to speak, and not all the children and recurse like that. I just can't figure it out. I know that this probably won't render right for you as you need the CSS and JS and all that, but I'm happy to share that with anyone that helps out to get this solved in an elegant way. Also other suggestions and improvements are welcome. I've attached a screen shot so you can see what it looks like. attachment: menu.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Unexpected results using ksort on arrays in which the keys are mixed alphanumeric strings.
I have been experimenting using four character alphanumeric keys on an array, and when I generated a random set of keys, and then used ksort to sort the array, I was very surprised to find that if the key contained any non-numeric character, or if it started with zero, the key was sorted as a base 36 number (0- 9, A-Z, as I expected. However if the key only contained numbers, and did not start with zero, it was sorted to the end of the list. Thus: 0009 000A 0999 09A0 ASDF 1000 I presume this is related to last weeks discussions about casting variables, but I cannot understand why 0999 should go to the start of the list, while 1000 goes to the end. Can anyone explain this logically? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why PHP won
On Mon, Feb 23, 2009 at 01:39:51PM -0800, Daevid Vincent wrote: http://startuplessonslearned.blogspot.com/2009/01/why-php-won.html I *like* the way this guy thinks. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ms-word reading from PHP on linux O.S
thanks Lucas.This code is very helpful to me.
Re: [PHP] Why PHP won
Paul M Foster wrote: On Mon, Feb 23, 2009 at 01:39:51PM -0800, Daevid Vincent wrote: http://startuplessonslearned.blogspot.com/2009/01/why-php-won.html I *like* the way this guy thinks. Paul It was a decent page. Point #2 though - you can use mod_rewrite to do wonders with respect to url presentation, and you can use DOMDocument to completely construct the page before sending it to the browser - allowing you to translate xhtml to html for browsers that don't properly support xhtml+xml. Avoiding mixing html with php really is better, and php does let you do that fairly easily. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ms-word reading from PHP on linux O.S
Srinivasa Rao D wrote: Hi all, * How better, i can read ms-word doc files from PHP on LINUX OS*. [snip] *Is there are any other softwares that can fetch text from MS-WORD file?.* OpenOffice. -- Per Jessen, Zürich (1.9°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why PHP won
Michael A. Peters wrote: [anip] and you can use DOMDocument to completely construct the page before sending it to the browser - allowing you to translate xhtml to html for browsers that don't properly support xhtml+xml. I suspect you meant translate xml to html? I publish everything in xhtml, no browser has had a problem with that yet. -- Per Jessen, Zürich (2.1°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php