Re: [PHP] OPTIMIZING - The fastest way to open and show a file
Richard Lynch wrote: On Fri, October 14, 2005 6:29 am, Ruben Rubio Rey wrote: if(file_exists($filename)){ $modified_date=filemtime($filename); if(time()<($modified_date+1 * 24 * 60 * 60)){ $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); echo $contents; } } Checking both file_exists and then doing fopen seems a bit silly. Trap the error from fopen, and just use that as your file_exists test. I suspect http://php.net/file_get_contents will be SLIGHTLY faster than doing all of this code, though: if (filemtime($filename) > time()) $contents = @file_get_contents($filename); if ($contents === false){ //error-handling code } else{ echo $contents; } Then, of course, we have to wonder if you NEED $contents for later use in the script. If not, something like this will clock in better: $bytes = @readfile($filename); if ($bytes === false){ //error-handling code } This seems to be the best solution. I do not need $content anymore. I ll post results. :) The difference here is that you don't even stuff the file into the PHP string. It's all read and passed out to stdout in low-level internal PHP C code, and the data never needs to hit "PHP" variables which are "more expensive" to setup and maintain. Note that which is REALLY fastest will probably depend on the size of the files, your OS system cache, your hardware, and maybe which version of PHP you are using, if the underlying functions changed. Must be nice to be worried about 0.0x milliseconds -- I'm fighting a mystery 3.0 seconds in a data feed for a search engine myself :-) Search engine ... thats the most complicated! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: OPTIMIZING - The fastest way to open and show a file
In a "almost idle desktop machine" always takes arround 0.04. The measured is on a server when it was with low traffic (average load arround 0.7) ac wrote: where did these time measured? on a heavily loaded server or on your own almost idle desktop machine ? On 10/14/05, Ruben Rubio Rey <[EMAIL PROTECTED]> wrote: Hi, I m creating a cache system, and i have a problem: PHP takes a lot of time opening the file. (Im using 2.6.9-1.667smp and XFS) * For files less or equal 6 Kb, takes arround 0.02-0.03 miliseconds - its ok * For files arround 35 Kb takes arround 0.2-0.4 miliseconds - too much. What can I do to make faster opening files? ** Source code: if(file_exists($filename)){ $modified_date=filemtime($filename); if(time()<($modified_date+1 * 24 * 60 * 60)){ $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); echo $contents; } } ** Thinks that I have tried: * fopen is *much* faster than include * filemtime is faster than filectime * Pear Cache its too much slower (0.5-0.7 milsecond per file) Thanks in advance Tk421 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- all born, to be dying -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] a couple of problems with PHP form
I am trying to set up some validation for my php form with the email field using the following code: if(!eregi("^(.+)@(.+)\\.(.+)$",$_POST['email'])) { $error_msg .= "Your email appears to be invalid."; $ok = "false"; } I am trying to accomplish not being able to enter anything other than a valid email string this doesn'r seem to be doing anything. also, I want the field to appear hilighted when there is no information so I am doing this: " and I have an error class set up in my CSS, such as .error {border: 1px solid red;} this is not doinf anything either. Can somone point out what may be wrong with this PHP code? thanks, -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Funky array question
one more thing... if you have php <5 and >= 3.0.6, you could use stristr for case insensitive comparison without having to deal with the slower and more cumbersome regex. On Oct 16, 2005, at 11:18 PM, Minuk Choi wrote: Assuming that you are also accepting partial matches... (e.g. if you had a sentence with something like, "Mr. LeBlue says hello", and that should be a match for "blue") If $mysqlString contains 1 sentence from the mySQL database(I assume you've a loop or something that'll fetch 1 string per iteration) $resultStr = $mysqlString; $bFound=false; foreach ($myArray as $colorArray) { $firstTerm = $colorArray[0]; $secondTerm = $colorArray[1]; if (strpos($resultStr, $firstTerm)!==false) { $resultStr = $secondTerm; $bFound=true; } if ($bFound) break; } $mysqlString = $resultStr; Try that. Brian Dunning wrote: I want to create an array like this: $myArray=array( array('orange','A very bright color'), array('blue','A nice color like the ocean'), array('yellow','Very bright like the sun') ...etc... ) Sort of like a small database in memory. Then I want to compare each of the rows coming out of a MySQL call, which are sentences, against this array to see if the FIRST TERM in each array element is present in the sentence, and then display the SECOND TERM from the array for each sentence. Make sense? So for these two sentences, and the above array, here's how I want it to output: "He used blue paint" - A nice color like the ocean. "The flower was yellow" - Very bright like the sun. Can someone help me out with the code needed to search the sentence to which FIRST TERM appears in it, and retrieve the SECOND TERM? I've tried too many things and now my brain is tied in a knot. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Funky array question
sorry, I am mistaken here. I forgot that "!==" is the same functionality as a "===", in that the comparison is made by value *and* type. On Oct 16, 2005, at 11:26 PM, Jordan Miller wrote: Also, note the warning on the man page. you would want to use a triple equals sign "!===false" because stripos could return a zero or an empty string which is actually "==false". -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Funky array question
Hello, what have you been trying for comparison so far that has not been working? if you have php 5, you would want to use stripos, which is case- INsensitive, not strpos, which is the opposite. Also, note the warning on the man page. you would want to use a triple equals sign "!===false" because stripos could return a zero or an empty string which is actually "==false". http://www.php.net/stripos/ if you do not have php 5, i would use regex so you can get case insensitivity. Jordan On Oct 16, 2005, at 11:18 PM, Minuk Choi wrote: Assuming that you are also accepting partial matches... (e.g. if you had a sentence with something like, "Mr. LeBlue says hello", and that should be a match for "blue") If $mysqlString contains 1 sentence from the mySQL database(I assume you've a loop or something that'll fetch 1 string per iteration) $resultStr = $mysqlString; $bFound=false; foreach ($myArray as $colorArray) { $firstTerm = $colorArray[0]; $secondTerm = $colorArray[1]; if (strpos($resultStr, $firstTerm)!==false) { $resultStr = $secondTerm; $bFound=true; } if ($bFound) break; } $mysqlString = $resultStr; Try that. Brian Dunning wrote: I want to create an array like this: $myArray=array( array('orange','A very bright color'), array('blue','A nice color like the ocean'), array('yellow','Very bright like the sun') ...etc... ) Sort of like a small database in memory. Then I want to compare each of the rows coming out of a MySQL call, which are sentences, against this array to see if the FIRST TERM in each array element is present in the sentence, and then display the SECOND TERM from the array for each sentence. Make sense? So for these two sentences, and the above array, here's how I want it to output: "He used blue paint" - A nice color like the ocean. "The flower was yellow" - Very bright like the sun. Can someone help me out with the code needed to search the sentence to which FIRST TERM appears in it, and retrieve the SECOND TERM? I've tried too many things and now my brain is tied in a knot. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Funky array question
Assuming that you are also accepting partial matches... (e.g. if you had a sentence with something like, "Mr. LeBlue says hello", and that should be a match for "blue") If $mysqlString contains 1 sentence from the mySQL database(I assume you've a loop or something that'll fetch 1 string per iteration) $resultStr = $mysqlString; $bFound=false; foreach ($myArray as $colorArray) { $firstTerm = $colorArray[0]; $secondTerm = $colorArray[1]; if (strpos($resultStr, $firstTerm)!==false) { $resultStr = $secondTerm; $bFound=true; } if ($bFound) break; } $mysqlString = $resultStr; Try that. Brian Dunning wrote: I want to create an array like this: $myArray=array( array('orange','A very bright color'), array('blue','A nice color like the ocean'), array('yellow','Very bright like the sun') ...etc... ) Sort of like a small database in memory. Then I want to compare each of the rows coming out of a MySQL call, which are sentences, against this array to see if the FIRST TERM in each array element is present in the sentence, and then display the SECOND TERM from the array for each sentence. Make sense? So for these two sentences, and the above array, here's how I want it to output: "He used blue paint" - A nice color like the ocean. "The flower was yellow" - Very bright like the sun. Can someone help me out with the code needed to search the sentence to which FIRST TERM appears in it, and retrieve the SECOND TERM? I've tried too many things and now my brain is tied in a knot. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] editor
It's also could be vim. -Original Message- From: Hodicska Gergely [mailto:[EMAIL PROTECTED] Sent: Saturday, October 15, 2005 9:48 PM To: php general help Subject: Re: [PHP] editor >> I read somewhere about an editor, which has built in support for >> phpdocumentator and creating unit test. Now I could not find it, I tried >> a lot using Google without success. > Could it be PHPEdit ? Yes, thx, this is the editor which I tried to find. I already get it last night, after I tried to google not "php editor unit test support", but only "php editor simpletest". Regards, Felhő -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Funky array question
I want to create an array like this: $myArray=array( array('orange','A very bright color'), array('blue','A nice color like the ocean'), array('yellow','Very bright like the sun') ...etc... ) Sort of like a small database in memory. Then I want to compare each of the rows coming out of a MySQL call, which are sentences, against this array to see if the FIRST TERM in each array element is present in the sentence, and then display the SECOND TERM from the array for each sentence. Make sense? So for these two sentences, and the above array, here's how I want it to output: "He used blue paint" - A nice color like the ocean. "The flower was yellow" - Very bright like the sun. Can someone help me out with the code needed to search the sentence to which FIRST TERM appears in it, and retrieve the SECOND TERM? I've tried too many things and now my brain is tied in a knot. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Silly regex giveing me a hard time
On 10/16/05, Darvin <[EMAIL PROTECTED]> wrote: > Dotan Cohen wrote: > > I have a list like this: > > 235 Some info > > 12323 other 5 things > > No number on this line! > > 43 something or other > > > > I need to remove the first number from each line, so that I will get this: > > Some info > > other 5 things > > No number on this line! > > something or other > > > > So I tried: > > $data=preg_replace("//n[ ]*[0-9][ ]*/", "", $data); > > > > That is (I think): any amount of spaces, followed by any number, > > followed by any amount of spaces. This doesn't seem to be the way to > > do it. Anybody have a better idea? Thanks. > > > > Dotan > > http://technology-sleuth.com > > Try > preg_replace("/^[ ]*[0-9]+[ ]*/", "", $data); > > It means: from the beginning of $data looks for space (if any), then > almost one number followed by space (if any). > > If you don't use ^ you may remove the number 5 'from other 5 things' > > Darvin > Thanks all for the help on this one! Darvin's pointing out about the ^ was great- I couldn't quite figure that one out. You guys are the greatest. Dotan http://technology-sleuth.com/internet/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Silly regex giveing me a hard time
Dotan Cohen wrote: I have a list like this: 235 Some info 12323 other 5 things No number on this line! 43 something or other I need to remove the first number from each line, so that I will get this: Some info other 5 things No number on this line! something or other So I tried: $data=preg_replace("//n[ ]*[0-9][ ]*/", "", $data); That is (I think): any amount of spaces, followed by any number, followed by any amount of spaces. This doesn't seem to be the way to do it. Anybody have a better idea? Thanks. Dotan http://technology-sleuth.com Try preg_replace("/^[ ]*[0-9]+[ ]*/", "", $data); It means: from the beginning of $data looks for space (if any), then almost one number followed by space (if any). If you don't use ^ you may remove the number 5 'from other 5 things' Darvin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Silly regex giveing me a hard time
Try this: ^[ ]*[0-9]*[ ]* This will also strip out any blank spaces at the beginning of the line. -- Anas Mughal On 10/16/05, Dotan Cohen <[EMAIL PROTECTED]> wrote: > > I have a list like this: > 235 Some info > 12323 other 5 things > No number on this line! > 43 something or other > > I need to remove the first number from each line, so that I will get this: > Some info > other 5 things > No number on this line! > something or other > > So I tried: > $data=preg_replace("//n[ ]*[0-9][ ]*/", "", $data); > > That is (I think): any amount of spaces, followed by any number, > followed by any amount of spaces. This doesn't seem to be the way to > do it. Anybody have a better idea? Thanks. > > Dotan > http://technology-sleuth.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > >
[PHP] Silly regex giveing me a hard time
I have a list like this: 235 Some info 12323 other 5 things No number on this line! 43 something or other I need to remove the first number from each line, so that I will get this: Some info other 5 things No number on this line! something or other So I tried: $data=preg_replace("//n[ ]*[0-9][ ]*/", "", $data); That is (I think): any amount of spaces, followed by any number, followed by any amount of spaces. This doesn't seem to be the way to do it. Anybody have a better idea? Thanks. Dotan http://technology-sleuth.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP-WIN] Is this a PHP bug?
It's because PHP is trying to convert different var types into a common var type and then compare them when you use ==. === means compare value AND type so that's why it fails. Your string, 'Some kind of string' is getting converted down to the lowest common denominator, an int. Since there are no numbers in the string to grab onto, it gets converted to nothing, an int value of zero. If you had $x = "0" or if $y had contained numbers at all, it wouldn't have passed. But this is why when you use $x.'' it works properly because now you have "0", it's been converted to a string value "0". Good catch on that though, shows good methodical debugging :) So in the future, either use === or be extra aware of your variable types and make sure you're comparing properly. Good luck! -TG = = = Original message = = = $x = 0; // Numeric zero $y = 'Some kind of string'; if ($x == $y) echo 'they equal using =='; if ($x === $y) echo 'they equal using ==='; The above will echo 'they equal using =='. The values don't look very equal to me. Can anyone explain the logic behind this? I'm heading home now but look forward to your explanations tomorrow. PS Incidently, to 'fix' it so it behaves as it should, you can code: if ($x.'' == $y.'') echo 'this will not print and all is good.'; Regards .. Ross ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] QF & FB duplicate element form
Hi guys! I'm getting crazy about the following error working with QuickForm + FrontBuilder for a sign up form. As usual, login / passwd are shown in form by FB: [..] $auth = DB_DataObject::factory('auth'); $fb_auth =& DB_DataObject_FormBuilder::create($auth); $frm_auth =& $fb_auth->getForm(); $auth->postGenerateForm(&$frm_auth,&$fb_auth); [] I need user retypes password, then I added postGenerateForm() function within Auth class. I also added preProcessForm() for encrypt passwd and it works. [.] function postGenerateForm(&$form,&$fb) { // FALLA!! Repite dos veces el campo $form->addElement('password', 'passwordR', 'Retype password', array('size'=>32, 'maxlenght'=>32)); $form->addRule('passwordR', 'Retype password', 'required'); $form->addRule(array('password', 'passwordR'), 'Password does not match.', 'compare'); } function preProcessForm(&$data) { if(isset($data['password'])) { if($data['password'] != $this->password) { $data['password'] = md5($data['password']); } } //igualar id_user(auth) e id_user(users) } [] I think this should be work fine but text element passwordR is shown three times instead two. If postGenerateForm() is not called then only one password element is shown. Does anybody know why? Thanks -- Jorge Gonzalez y Hurtado de Mendoza [EMAIL PROTECTED] http://www.la-nevera.com soon on your screen http://www.webgout.com, check it out -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] No redirect with header()
On Sun, Oct 16, 2005 at 05:25:12PM +0200, Dotan Cohen wrote: > You say that it worked for you? Where did it take you? It _should_ > take you to another lyrics site. Did you stay on http://lyricslist.com > or go somewhere else? If I go to lyricslist.com and click the logo or the "Song Lyrics" link, then I get redirected to lyricsfreak.com. No blank pages, and the URL in my address bar changes too. Paul -- Rogue Tory http://www.roguetory.org.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] No redirect with header()
On 10/16/05, Paul Waring <[EMAIL PROTECTED]> wrote: > On Sun, Oct 16, 2005 at 05:04:09PM +0200, Dotan Cohen wrote: > > header ("Location: ".$url); > > ?> > > > > Does this seem like it should work? It doesn't. What is the correct > > syntax for these things? > > That code should work, and the example on your site seems to work for > me. The only thing you should make sure is that $url is an absolute URL, > even if you're redirecting within your own site (e.g. you shouldn't use > ../lyrics/ or /lyrics/) - you may be able to get away without doing this > but it's not the "correct" way to do things. > > You may want to change your code to this: > > header("Location: $url"); // no point in concatenating since double > quotes will interpolate the value of $url anyway > exit(); > > I can't remember why, but calling the exit(); function fixed a problem I > was having a while back when I was being sent to the right URL but the > old one was staying in my browser address bar. > > Paul > > Rogue Tory > http://www.roguetory.org.uk > Thanks, Paul. I stuck $url inside the double quotes, like you said. I also added the exit; function. No go for me. I get a blank page. You say that it worked for you? Where did it take you? It _should_ take you to another lyrics site. Did you stay on http://lyricslist.com or go somewhere else? Thank you. Dotan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] No redirect with header()
On Sun, Oct 16, 2005 at 05:04:09PM +0200, Dotan Cohen wrote: > header ("Location: ".$url); > ?> > > Does this seem like it should work? It doesn't. What is the correct > syntax for these things? That code should work, and the example on your site seems to work for me. The only thing you should make sure is that $url is an absolute URL, even if you're redirecting within your own site (e.g. you shouldn't use ../lyrics/ or /lyrics/) - you may be able to get away without doing this but it's not the "correct" way to do things. You may want to change your code to this: header("Location: $url"); // no point in concatenating since double quotes will interpolate the value of $url anyway exit(); I can't remember why, but calling the exit(); function fixed a problem I was having a while back when I was being sent to the right URL but the old one was staying in my browser address bar. Paul -- Rogue Tory http://www.roguetory.org.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Caching problems .. I think
SOunds like your form is using POST which does what you desribe to avoid submitting the same info twice. only way I know is to use GET but that would put al data in the URL. Søren Schimkat wrote: Hi guys I have a rather simple setup: A few forms chained after each other (the first leds to the second which leeds to the third and so on) I´m using sessions - and starting each page like this: header('Expires: ' . gmdate('D, d M Y H:i:s', (time() + (60 * 10))) . ' GMT'); session_cache_limiter('private_no_expire'); session_start(); ... which I believe gives each page (and form result) a caching time of 10 minutes. The problem is that when using the back button in IE - IE complains about the page and tells med that this page is the result of a form and that the content has been blocked. Can anyone tell me how to awoid this problem, so the backbutton can be used, and stil give each page a caching time of 10 minutes? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] No redirect with header()
I am working on a redirect script to log "out"'s. I was trying to do it with a header redirect: Does this seem like it should work? It doesn't. What is the correct syntax for these things? You can see the 'prototype' at http://lyricslist.com: Just click on the logo or the word "Song Lyrics" above the ads. Thanks in advance for any help. Dotan Cohen. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Caching problems .. I think
Hi guys I have a rather simple setup: A few forms chained after each other (the first leds to the second which leeds to the third and so on) I´m using sessions - and starting each page like this: header('Expires: ' . gmdate('D, d M Y H:i:s', (time() + (60 * 10))) . ' GMT'); session_cache_limiter('private_no_expire'); session_start(); ... which I believe gives each page (and form result) a caching time of 10 minutes. The problem is that when using the back button in IE - IE complains about the page and tells med that this page is the result of a form and that the content has been blocked. Can anyone tell me how to awoid this problem, so the backbutton can be used, and stil give each page a caching time of 10 minutes? -- Regards Søren Schimkat www.schimkat.dk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: RegEx - Is this right?
I don't know if these are equal. What about \r\n line endings? And what about \r line endings (from old Macs)? I guess file() handles all of these cases (didn't test it though) and your code doesn't (with \r you'll get a one line file!). AllOlli -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: ampersand in dom with utf-8
try this, if you need more entities to be included, just refer to `http://www.w3.org/2003/entities/iso8879/isolat1.ent' or find out its charcode by yourself. ]> farm lettuces with reed avocado, crème fraîche, radish and cilantro On 10/13/05, jonathan <[EMAIL PROTECTED]> wrote: > I'm now getting this error: > > XML Parsing Error: undefined entity > > with the following entity at the first ampersand: > farm lettuces with reed avocado, crème > fraîche, radish and cilantro > > Why is an ampersand considered an undefined entity? The xml version > is: > > Any thoughts please? > > -jonathan > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- all born, to be dying -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php