[PHP] PHPDoc way to describe the magic getter/setters [SOLVED]
I use a base.class that most classes extend from. That class uses the lovely Magic Methods for overloading __get() and __set() http://php.net/manual/en/language.oop5.magic.php However (in Zend Studio for example) when I try to auto-assist a property $foo I don't see that it has a get() or set() method. I'd like to see something like $this-get_foo() or $this-set_foo() and also if possible have them show up in the Outline tab window. Then I randomly stumbled upon this PHPDoc @ method tag and my whole world is brighter today than it has been for the past, oh let's say DECADE! http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags .method.pkg.html or @property too. http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags .property.pkg.html *giddy!* (now I just have to go back through all my code and update the class documentation headers everywhere) ?php /** * This is an example of how to use PHPDoc to describe the magic __get() and __set() * so that Zend Studio / Eclipse / Other IDEs can utilize the methods that don't technically exist. * * @methodvoid set_name() set_name(string $name) magic setter for $name property * @methodstring get_name() get_name() magic getter for $name property * * @link http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags .method.pkg.html * @link http://manual.phpdoc.org/HTMLSmartyConverter/PHP/phpDocumentor/tutorial_tags .property.pkg.html */ class foo { /** * @var string $name the description of $name goes here */ protected $name; public function __construct($id = NULL) { } } $myobj = new foo(); Put your cursor after the - and hit CTRL+SPACE. Notice how you have magic get_name() and set_name($name) appearing and also in the Eclipse Outline pane $myobj- You're welcome. ?
RE: [PHP] refernces, arrays, and why does it take up so much memory? [SOLVED]
EUREKA! -Original Message- From: Stuart Dallas [mailto:stu...@3ft9.com] Sent: Tuesday, September 03, 2013 6:31 AM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] refernces, arrays, and why does it take up so much memory? On 3 Sep 2013, at 02:30, Daevid Vincent dae...@daevid.com wrote: I'm confused on how a reference works I think. I have a DB result set in an array I'm looping over. All I simply want to do is make the array key the id of the result set row. This is the basic gist of it: private function _normalize_result_set() { foreach($this-tmp_results as $k = $v) { $id = $v['id']; $new_tmp_results[$id] = $v; //2013-08-29 [dv] using a reference here cuts the memory usage in half! You are assigning a reference to $v. In the next iteration of the loop, $v will be pointing at the next item in the array, as will the reference you're storing here. With this code I'd expect $new_tmp_results to be an array where the keys (i.e. the IDs) are correct, but the data in each item matches the data in the last item from the original array, which appears to be what you describe. unset($this-tmp_results[$k]); Doing this for every loop is likely very inefficient. I don't know how the inner workings of PHP process something like this, but I wouldn't be surprised if it's allocating a new chunk of memory for a version of the array without this element. You may find it better to not unset anything until the loop has finished, at which point you can just unset($this- tmp_results). /* if ($i++ % 1000 == 0) { gc_enable(); // Enable Garbage Collector var_dump(gc_enabled()); // true var_dump(gc_collect_cycles()); // # of elements cleaned up gc_disable(); // Disable Garbage Collector } */ } $this-tmp_results = $new_tmp_results; //var_dump($this-tmp_results); exit; unset($new_tmp_results); } Try this: private function _normalize_result_set() { // Initialise the temporary variable. $new_tmp_results = array(); // Loop around just the keys in the array. foreach (array_keys($this-tmp_results) as $k) { // Store the item in the temporary array with the ID as the key. // Note no pointless variable for the ID, and no use of ! $new_tmp_results[$this-tmp_results[$k]['id']] = $this-tmp_results[$k]; } // Assign the temporary variable to the original variable. $this-tmp_results = $new_tmp_results; } I'd appreciate it if you could plug this in and see what your memory usage reports say. In most cases, trying to control the garbage collection through the use of references is the worst way to go about optimising your code. In my code above I'm relying on PHPs copy-on-write feature where data is only duplicated when assigned if it changes. No unsets, just using scope to mark a variable as able to be cleaned up. Where is this result set coming from? You'd save yourself a lot of memory/time by putting the data in to this format when you read it from the source. For example, if reading it from MySQL, $this- tmp_results[$row['id']] = $row when looping around the result set. Also, is there any reason why you need to process this full set of data in one go? Can you not break it up in to smaller pieces that won't put as much strain on resources? -Stuart There were reasons I had the $id -- I only showed the relevant parts of the code for sake of not overly complicating what I was trying to illustrate. There is other processing that had to be done too in the loop and that is also what I illustrated. Here is your version effectively: private function _normalize_result_set() //Stuart { if (!$this-tmp_results || count($this-tmp_results) 1) return; $new_tmp_results = array(); // Loop around just the keys in the array. $D_start_mem_usage = memory_get_usage(); foreach (array_keys($this-tmp_results) as $k) { /* if ($this-tmp_results[$k]['genres']) { // rip through each scene's `genres` and store them as an array since we'll need'em later too $g = explode('|', $this-tmp_results[$k]['genres']); array_pop($g); // there is an extra '' element due to the final | character. :-\ $this-tmp_results[$k]['g'] = $g; } */ // Store
RE: [PHP] refernces, arrays, and why does it take up so much memory? [SOLVED]
-Original Message- From: Stuart Dallas [mailto:stu...@3ft9.com] Sent: Tuesday, September 03, 2013 2:37 PM To: Daevid Vincent Cc: php-general@lists.php.net; 'Jim Giner' Subject: Re: [PHP] refernces, arrays, and why does it take up so much memory? [SOLVED] On 3 Sep 2013, at 21:47, Daevid Vincent dae...@daevid.com wrote: There were reasons I had the $id -- I only showed the relevant parts of the code for sake of not overly complicating what I was trying to illustrate. There is other processing that had to be done too in the loop and that is also what I illustrated. Here is your version effectively: private function _normalize_result_set() //Stuart { if (!$this-tmp_results || count($this-tmp_results) 1) return; $new_tmp_results = array(); // Loop around just the keys in the array. $D_start_mem_usage = memory_get_usage(); foreach (array_keys($this-tmp_results) as $k) { You could save another, relatively small, chunk of memory by crafting your loop with the rewind, key, current and next methods (look them up to see what they do). Using those you won't need to make a copy of the array keys as done in the above line. When you've got the amount of data you're dealing with it may be worth investing that time. /* if ($this-tmp_results[$k]['genres']) { // rip through each scene's `genres` and store them as an array since we'll need'em later too $g = explode('|', $this-tmp_results[$k]['genres']); array_pop($g); // there is an extra '' element due to the final | character. :-\ Then remove that from the string before you explode. Munging arrays is expensive, both computationally and in terms of memory usage. $this-tmp_results[$k]['g'] = $g; Get rid of the temporary variable again - there's no need for it. $this-tmp_results[$k]['g'] = explode('|', trim($this- tmp_results[$k]['genres'], '|')); Maybe an option. I'll look into trim() the last | off the tmp_results in a loop at the top. Not sure if changing the variable will have the same effect as adding one does. Interesting to see... If this is going in to a class, and you have control over how it's accessed, you have the ability to do this when the value is accessed. This means you won't need to } */ // Store the item in the temporary array with the ID as the key. // Note no pointless variable for the ID, and no use of ! $new_tmp_results[$this-tmp_results[$k]['id']] = $this-tmp_results[$k]; } // Assign the temporary variable to the original variable. $this-tmp_results = $new_tmp_results; echo \nMEMORY USED FOR STUART's version: .number_format(memory_get_usage() - $D_start_mem_usage). PEAK: (.number_format(memory_get_peak_usage(true)).)br\n; var_dump($this-tmp_results); exit(); } MEMORY USED FOR STUART's version: -128 PEAK: (90,439,680) With the processing in the genres block MEMORY USED FOR STUART's version: 97,264,368 PEAK: (187,695,104) So a slight improvement from the original of -28,573,696 MEMORY USED FOR _normalize_result_set(): 97,264,912 PEAK: (216,268,800) Awesome. No matter what I tried however it seems that frustratingly just the simple act of adding a new hash to the array is causing a significant memory jump. That really blows! Therefore my solution was to not store the $g as ['g'] -- which would seem to be the more efficient way of doing this once and re- use the array over and over, but instead I am forced to inline rip through and explode() in three different places of my code. Consider what you're asking PHP to do. You're taking an element in the middle of an array structure in memory and asking PHP to make it bigger. What's PHP going to do? It's going to copy the entire array to a new location in memory with an additional amount reserved for what you're adding. Note that this is just a guess - it's entirely possible that PHP manages it's memory better than that, but I wouldn't count on it. We get over 30,000 hits per second, and even with lots of caching, 216MB vs 70-96MB is significant and the speed hit is only about 1.5 seconds more per page. Here are three distinctly different example pages that exercise different parts of the code path: PAGE RENDERED IN 7.0466279983521 SECONDS MEMORY USED @START: 262,144 - @END: 26,738,688 = 26,476,544 BYTES MEMORY PEAK USAGE: 69,730,304 BYTES PAGE RENDERED IN 6.9327299594879 SECONDS MEMORY USED @START: 262,144 - @END: 53,739,520 = 53,477,376 BYTES MEMORY PEAK
RE: [PHP] refernces, arrays, and why does it take up so much memory? [SOLVED]
-Original Message- From: Daevid Vincent [mailto:dae...@daevid.com] Sent: Tuesday, September 03, 2013 4:03 PM To: php-general@lists.php.net Cc: 'Stuart Dallas' Subject: RE: [PHP] refernces, arrays, and why does it take up so much memory? [SOLVED] $this-tmp_results[$k]['g'] = explode('|', trim($this- tmp_results[$k]['genres'], '|')); Maybe an option. I'll look into trim() the last | off the tmp_results in a loop at the top. Not sure if changing the variable will have the same effect as adding one does. Interesting to see... Here are the results of that. Interesting changes. Overall it's a slight improvement, but most significant on the middle one, so still a worthy keeper. Odd that it wouldn't be improvement across the board though. PHP is kookie. PAGE RENDERED IN 7.1903319358826 SECONDS MEMORY USED @START: 262,144 - @END: 27,000,832 = 26,738,688 BYTES MEMORY PEAK USAGE: 69,992,448 BYTES PAGE RENDERED IN 6.5189208984375 SECONDS MEMORY USED @START: 262,144 - @END: 42,729,472 = 42,467,328 BYTES MEMORY PEAK USAGE: 78,905,344 BYTES PAGE RENDERED IN 7.5954079627991 SECONDS MEMORY USED @START: 262,144 - @END: 50,331,648 = 50,069,504 BYTES MEMORY PEAK USAGE: 96,206,848 BYTES Old. PAGE RENDERED IN 7.0466279983521 SECONDS MEMORY USED @START: 262,144 - @END: 26,738,688 = 26,476,544 BYTES MEMORY PEAK USAGE: 69,730,304 BYTES PAGE RENDERED IN 6.9327299594879 SECONDS MEMORY USED @START: 262,144 - @END: 53,739,520 = 53,477,376 BYTES MEMORY PEAK USAGE: 79,167,488 BYTES PAGE RENDERED IN 7.55816092 SECONDS MEMORY USED @START: 262,144 - @END: 50,855,936 = 50,593,792 BYTES MEMORY PEAK USAGE: 96,206,848 BYTES
[PHP] refernces, arrays, and why does it take up so much memory?
I'm confused on how a reference works I think. I have a DB result set in an array I'm looping over. All I simply want to do is make the array key the id of the result set row. This is the basic gist of it: private function _normalize_result_set() { foreach($this-tmp_results as $k = $v) { $id = $v['id']; $new_tmp_results[$id] = $v; //2013-08-29 [dv] using a reference here cuts the memory usage in half! unset($this-tmp_results[$k]); /* if ($i++ % 1000 == 0) { gc_enable(); // Enable Garbage Collector var_dump(gc_enabled()); // true var_dump(gc_collect_cycles()); // # of elements cleaned up gc_disable(); // Disable Garbage Collector } */ } $this-tmp_results = $new_tmp_results; //var_dump($this-tmp_results); exit; unset($new_tmp_results); } Without using the = reference, my data works great: $new_tmp_results[$id] = $v; array (size=79552) 6904 = array (size=4) 'id' = string '6904' (length=4) 'studio_id' = string '5' (length=1) 'genres' = string '34|' (length=3) 6905 = array (size=4) 'id' = string '6905' (length=4) 'studio_id' = string '5' (length=1) 'genres' = string '6|37|' (length=5) However it takes a stupid amount of memory for some unknown reason. MEMORY USED @START: 262,144 - @END: 42,729,472 = 42,467,328 BYTES MEMORY PEAK USAGE: 216,530,944 BYTES When using the reference the memory drastically goes down to what I'd EXPECT it to be (and actually the problem I'm trying to solve). MEMORY USED @START: 262,144 - @END: 6,029,312 = 5,767,168 BYTES MEMORY PEAK USAGE: 82,051,072 BYTES However my array is all kinds of wrong: array (size=79552) 6904 = array (size=4) 'id' = string '86260' (length=5) 'studio_id' = string '210' (length=3) 'genres' = string '8|9|10|29|58|' (length=13) 6905 = array (size=4) 'id' = string '86260' (length=5) 'studio_id' = string '210' (length=3) 'genres' = string '8|9|10|29|58|' (length=13) Notice that they're all the same values, although the keys seem right. I don't understand why that happens because foreach($this-tmp_results as $k = $v) Should be changing $v each iteration I'd think. Honestly, I am baffled as to why those unsets() make no difference. All I can think is that the garbage collector doesn't run. But then I had also tried to force gc() and that still made no difference. *sigh* I had some other cockamamie idea where I'd use the same tmp_results array in a tricky way to avoid a second array. The concept being I'd add 1 million to the ['id'] (which we want as the new array key), then unset the existing sequential key, then when all done, loop through and shift all the keys by 1 million thereby they'd be the right index ID. So add one and unset one immediately after. Clever right? 'cept it too made no difference on memory. Same thing is happening as above where the gc() isn't running or something is holding all that memory until the end. *sigh* Then I tried a different way using array_combine() and noticed something very disturbing. http://www.php.net/manual/en/function.array-combine.php private function _normalize_result_set() { if (!$this-tmp_results || count($this-tmp_results) 1) return; $D_start_mem_usage = memory_get_usage(); foreach($this-tmp_results as $k = $v) { $id = $v['id']; $tmp_keys[] = $id; if ($v['genres']) { $g = explode('|', $v['genres']); $this-tmp_results[$k]['g'] = $g; //this causes a massive spike in memory usage } } //var_dump($tmp_keys, $this-tmp_results); exit; echo \nMEMORY USED BEFORE array_combine: .number_format(memory_get_usage() - $D_start_mem_usage). PEAK: (.number_format(memory_get_peak_usage(true)).)br\n; $this-tmp_results = array_combine($tmp_keys, $this-tmp_results); echo \nMEMORY USED FOR array_combine: .number_format(memory_get_usage() - $D_start_mem_usage). PEAK: (.number_format(memory_get_peak_usage(true)).)br\n; var_dump($tmp_keys, $this-tmp_results); exit; } Just the simple act of adding that 'g' variable element to the array causes a massive change in memory usage. WHAT THE F!? MEMORY USED BEFORE array_combine: 105,315,264 PEAK: (224,395,264) MEMORY USED FOR array_combine: 106,573,040 PEAK: (224,395,264) And taking out the $this-tmp_results[$k]['g'] = $g; Results in MEMORY USED BEFORE array_combine:
RE: [PHP] Re: refernces, arrays, and why does it take up so much memory?
-Original Message- From: Jim Giner [mailto:jim.gi...@albanyhandball.com] Sent: Monday, September 02, 2013 8:14 PM To: php-general@lists.php.net Subject: [PHP] Re: refernces, arrays, and why does it take up so much memory? On 9/2/2013 9:30 PM, Daevid Vincent wrote: I'm confused on how a reference works I think. I have a DB result set in an array I'm looping over. All I simply want to do is make the array key the id of the result set row. This is the basic gist of it: private function _normalize_result_set() { foreach($this-tmp_results as $k = $v) { $id = $v['id']; $new_tmp_results[$id] = $v; //2013-08-29 [dv] using a reference here cuts the memory usage in half! unset($this-tmp_results[$k]); /* if ($i++ % 1000 == 0) { gc_enable(); // Enable Garbage Collector var_dump(gc_enabled()); // true var_dump(gc_collect_cycles()); // # of elements cleaned up gc_disable(); // Disable Garbage Collector } */ } $this-tmp_results = $new_tmp_results; //var_dump($this-tmp_results); exit; unset($new_tmp_results); } Without using the = reference, my data works great: $new_tmp_results[$id] = $v; array (size=79552) 6904 = array (size=4) 'id' = string '6904' (length=4) 'studio_id' = string '5' (length=1) 'genres' = string '34|' (length=3) 6905 = array (size=4) 'id' = string '6905' (length=4) 'studio_id' = string '5' (length=1) 'genres' = string '6|37|' (length=5) However it takes a stupid amount of memory for some unknown reason. MEMORY USED @START: 262,144 - @END: 42,729,472 = 42,467,328 BYTES MEMORY PEAK USAGE: 216,530,944 BYTES When using the reference the memory drastically goes down to what I'd EXPECT it to be (and actually the problem I'm trying to solve). MEMORY USED @START: 262,144 - @END: 6,029,312 = 5,767,168 BYTES MEMORY PEAK USAGE: 82,051,072 BYTES However my array is all kinds of wrong: array (size=79552) 6904 = array (size=4) 'id' = string '86260' (length=5) 'studio_id' = string '210' (length=3) 'genres' = string '8|9|10|29|58|' (length=13) 6905 = array (size=4) 'id' = string '86260' (length=5) 'studio_id' = string '210' (length=3) 'genres' = string '8|9|10|29|58|' (length=13) Notice that they're all the same values, although the keys seem right. I don't understand why that happens because foreach($this-tmp_results as $k = $v) Should be changing $v each iteration I'd think. Honestly, I am baffled as to why those unsets() make no difference. All I can think is that the garbage collector doesn't run. But then I had also tried to force gc() and that still made no difference. *sigh* I had some other cockamamie idea where I'd use the same tmp_results array in a tricky way to avoid a second array. The concept being I'd add 1 million to the ['id'] (which we want as the new array key), then unset the existing sequential key, then when all done, loop through and shift all the keys by 1 million thereby they'd be the right index ID. So add one and unset one immediately after. Clever right? 'cept it too made no difference on memory. Same thing is happening as above where the gc() isn't running or something is holding all that memory until the end. *sigh* Then I tried a different way using array_combine() and noticed something very disturbing. http://www.php.net/manual/en/function.array-combine.php private function _normalize_result_set() { if (!$this-tmp_results || count($this-tmp_results) 1) return; $D_start_mem_usage = memory_get_usage(); foreach($this-tmp_results as $k = $v) { $id = $v['id']; $tmp_keys[] = $id; if ($v['genres']) { $g = explode('|', $v['genres']); $this-tmp_results[$k]['g'] = $g; //this causes a massive spike in memory usage } } //var_dump($tmp_keys, $this-tmp_results); exit; echo \nMEMORY USED BEFORE array_combine: .number_format(memory_get_usage() - $D_start_mem_usage). PEAK: (.number_format(memory_get_peak_usage(true)).)br\n; $this-tmp_results = array_combine($tmp_keys, $this-tmp_results); echo \nMEMORY USED
RE: [PHP] [SOLVED] need some regex help to strip out // comments but not http:// urls
-Original Message- From: Andreas Perstinger [mailto:andiper...@gmail.com] Sent: Tuesday, May 28, 2013 11:10 PM To: php-general@lists.php.net Subject: Re: [PHP] need some regex help to strip out // comments but not http:// urls On 28.05.2013 23:17, Daevid Vincent wrote: I want to remove all comments of the // variety, HOWEVER I don't want to remove URLs... You need a negative look behind assertion ( http://www.php.net/manual/en/regexp.reference.assertions.php ). (?!http:)// will match // only if it isn't preceded by http:. Bye, Andreas This worked like a CHAMP Andreas my friend! You are a regex guru! -Original Message- From: Sean Greenslade [mailto:zootboys...@gmail.com] Sent: Wednesday, May 29, 2013 10:28 AM Also, (I haven't tested it, but) I don't think that example you gave would work. Without any sort of quoting around the http://; , I would assume the JS interpreter would take that double slash as a comment starter. Do tell me if I'm wrong, though. You're wrong Sean. :-p This regex works in all cases listed in my example target string. \s*(?!:)//.*?$ Or in my actual compress() method: $sBlob = preg_replace(@\s*(?!:)//.*?$@m,'',$sBlob); Target test case with intentional traps: // another comment here iframe src=http://foo.com; function bookmarksite(title,url){ if (window.sidebar) // firefox window.sidebar.addPanel(title, url, ); else if(window.opera window.print){ // opera var elem = document.createElement('a'); elem.setAttribute('href',url); elem.setAttribute('title',title); elem.setAttribute('rel','sidebar'); elem.click(); } else if(document.all)// ie window.external.AddFavorite(url, title); } And for those interested here is the whole method... public function compress($sBlob) { //remove C style /* */ blocks as well as PHPDoc /** */ blocks $sBlob = preg_replace(@/\*(.*?)\*/@s,'',$sBlob); //$sBlob = preg_replace(/\*[^*]*\*+(?:[^*/][^*]*\*+)*/s,'',$sBlob); //$sBlob = preg_replace(/\\*(?:.|[\\n\\r])*?\\*/s,'',$sBlob); //remove // or # style comments at the start of a line possibly redundant with next preg_replace $sBlob = preg_replace(@^\s*((^\s*(#+|//+)\s*.+?$\n)+)@m,'',$sBlob); //remove // style comments that might be tagged onto valid code lines. we don't try for # style as that's risky and not widely used // @see http://www.php.net/manual/en/regexp.reference.assertions.php $sBlob = preg_replace(@\s*(?!:)//.*?$@m,'',$sBlob); if (in_array($this-_file_name_suffix, array('html','htm'))) { //remove !-- -- blocks $sBlob = preg_replace(/!--[^\[](.*?)--/s,'',$sBlob); //if Tidy is enabled... //if (!extension_loaded('tidy')) dl( ((PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '') . 'tidy.' . PHP_SHLIB_SUFFIX); if (FALSE extension_loaded('tidy')) { //use Tidy to clean up the rest. There may be some redundancy with the above, but it shouldn't hurt //See all parameters available here: http://tidy.sourceforge.net/docs/quickref.html $tconfig = array( 'clean' = true, 'hide-comments' = true, 'hide-endtags' = true, 'drop-proprietary-attributes' = true, 'join-classes' = true, 'join-styles' = true, 'quote-marks' = false, 'fix-uri' = false, 'numeric-entities' = true, 'preserve-entities' = true, 'doctype' = 'omit', 'tab-size' = 1, 'wrap' = 0, 'wrap-php' = false, 'char-encoding' = 'raw', 'input-encoding' = 'raw', 'output-encoding' = 'raw', 'ascii-chars' = true, 'newline' = 'LF', 'tidy-mark' = false, 'quiet' = true, 'show-errors' = ($this-_debug ? 6 : 0), 'show-warnings' = $this-_debug, ); if ($this-_log_messages) $tconfig['error-file'] = DBLOGPATH
[PHP] need some regex help to strip out // comments but not http:// urls
I'm adding some minification to our cache.class.php and am running into an edge case that is causing me grief. I want to remove all comments of the // variety, HOWEVER I don't want to remove URLs... Given some example text here with carefully crafted cases: // another comment here iframe src=http://foo.com; function bookmarksite(title,url){ if (window.sidebar) // firefox window.sidebar.addPanel(title, url, ); else if(window.opera window.print){ // opera var elem = document.createElement('a'); elem.setAttribute('href',url); elem.setAttribute('title',title); elem.setAttribute('rel','sidebar'); elem.click(); } else if(document.all)// ie window.external.AddFavorite(url, title); } I've tried so many variations and hunted on StackOverflow, Google, etc. and what would seem like a task already solved, doesn't seem to be. This is close, but still matches //foo.com (omitting the : of course) \s*(?!:)//.*?$ (count it as '/m' multiline) This ultimately ends up in a PHP line of code like so: $sBlob = preg_replace(@\s*//.*?$@m,'',$sBlob); Here are some other links of stuff I've found and tried to experiment with varying degrees. http://stackoverflow.com/questions/4568410/match-comments-with-regex-but-not -inside-a-quote http://stackoverflow.com/questions/611883/regex-how-to-match-everything-exce pt-a-particular-pattern http://stackoverflow.com/questions/11863847/regex-to-match-urls-but-not-urls -in-hyperlinks http://stackoverflow.com/questions/643113/regex-to-strip-comments-and-multi- line-comments-and-empty-lines -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] need some regex help to strip out // comments but not http:// urls
From: David Harkness [mailto:davi...@highgearmedia.com] We have been using a native jsmin extension [1] which does a lot more without any trouble for over two years now. It's much faster than the equivalent PHP solution and is probably tested by a lot more people than a home-grown version. You might want to check it out before going too far down this path. Good luck, David [1] http://www.ypass.net/software/php_jsmin/ I appreciate the pointer, but our files, like many people, is a mixture of HTML, PHP and JS in one file. This jsmin appears to only work on .js files right? Also, everything else works great in our minifing method, just this edge case. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How do I remove a string from another string in a fuzzy way?
We have a support ticket system we built and customers can reply via email which then posts their reply into our database. The problem is that when you read a ticket, you see each ticket entry (row in DB) but they tend to accumulate the previous entries text since the customer replied to an email. A thread if you will. I'm trying to strip out the duplicate parts (cosmetically on the front end via a checkbox, in case the support person needs to see the actual unaltered version such as in cases where the algorithm may be too aggressive and rip out important pieces inadvertently). One challenge I'm running into are situations like this, where the text is embedded but has been slightly altered. ENTRY 1: For security and confidentiality reasons, we request that all subscribers who are requesting cancellation do so via the website of the company billing their account. You can easily cancel your membership on our billing agent website (just in case THIS PHP list software mangles the above, it is just one long string with no CR breaks as the ones below have) ENTRY 2: (which was mangled by the customer's email client most likely and formatted for 72 chars) For security and confidentiality reasons, we request that all subscribers who are requesting cancellation do so via the website of the company billing their account. You can easily cancel your membership on our billing agent website This is a simple example, but the solution logic might extend to other things such as perhaps a prefix like so: ENTRY 3: (again mangled by email client to prefix with marks) For security and confidentiality reasons, we request that all subscribers who are requesting cancellation do so via the website of the company billing their account. You can easily cancel your membership on our billing agent website Keep in mind those blobs of text are often embedded inside other text which I *do* want to display. Initially I was thinking that somehow I could use a simple regex on the needle and haystacks to strip out all white space and str_ireplace() them that way, but then I don't have a way to put the whitespace back that I can see. Currently I'm just sort of brute forcing it and comparing the current message to previous ones and if the previous message is found in this message, then blank it out. But this only works of course if they are identical. ?php $i = 0; //the initial ticket message is in a different table than the replies hereafter $entry_message[$i] = $my_ticket-get_message(false); foreach($my_ticket-get_entries() as $eid = $entry) { $i++; $output_message = $entry_message[$i] = trim($entry['message']); //var_dump('OUTPUT MESSAGE:', $output_message); for ($j = ($i - 1); $j = 0; --$j) { //echo \nbrfont color='green'bsearching for entry_message[$j] in [i = $i]:/bbr\n$output_message/fontbr\n; $output_message = str_replace($entry_message[$j], '', $output_message); //var_dump('NEW OUTPUT MESSAGE:', $output_message); } ( ^ you have to start from the bottom up like that or else you have altered your $output_message so subsequent matches fail ^ ) Would these be helpful? http://us2.php.net/manual/en/function.similar-text.php http://us2.php.net/manual/en/function.levenshtein.php http://us2.php.net/manual/en/function.soundex.php http://us2.php.net/manual/en/function.metaphone.php It seems like similar_text() could be, and if it's a high percentage, consider it a match, but then how do I extract that part from the source string, since str_replace() requires an exact match, not fuzzy. I am also thinking maybe something with preg_replace() where I break up the source string and take the first word(s) and last word(s) and use .*? in between, but that has its' own challenges for example... /For .*? website/ On this text doesn't do the match I really want (it stops on the second line)... For security and confidentiality reasons, we request that all subscribers who are requesting cancellation do so via the website of the company billing their account. You can easily cancel your membership on our billing agent website More stuff goes here website By putting more words before and after the .*? I could get better accuracy, but that is starting to feel hacky or fragile somehow. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How do I remove a string from another string in a fuzzy way?
-Original Message- From: muquad...@gmail.com [mailto:muquad...@gmail.com] On Behalf Of shiplu Sent: Monday, May 20, 2013 9:03 PM To: Daevid Vincent Cc: php-general General List Subject: Re: [PHP] How do I remove a string from another string in a fuzzy way? Is your ticketing system written from scratch? Because such type of logic is already implemented in existing help desk softwares. Yes written from scratch years ago. I think you can also use a specific string in your email to define which part goes in ticket and which part not. For example, you can include PLEASE REPLY ABOVE THIS LINE\r\n in each of the email. When reply comes you can split the whole email with this string and get the first part as original reply. We have like 20,000 tickets in there already. Asking the users (who are not the brightest people on the planet to begin with given the vast majority of tickets I've encountered. Most don't read simple instructions as it is and many don't even speak Engrish) to follow some instructions is probably not going to work. And even if it did, that doesn't solve the problem for previous tickets. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Need a tool to minimize HTML before storing in memecache
-Original Message- From: Marco Behnke [mailto:ma...@behnke.biz] Sent: Friday, May 03, 2013 12:56 PM Maybe google page speed is worth a look for you too? We have over 1,000 servers in house and also distributed across nodes in various cities and countries. Don't know if this is an answer to my question? You know what google page speed is about? At first I thought it was just like Y-slow which we already use, but that's orthogonal to what we're trying to achieve by minimizing the code. Then this caught my eye as we use both of these servers and any kind of automated module is preferred over manually re-writing pages: https://developers.google.com/speed/pagespeed/mod https://developers.google.com/speed/pagespeed/ngx thanks, I'll look into that as well. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Need a tool to minimize HTML before storing in memecache
Well we get about 30,000 page hits PER SECOND. So we have a template engine that generates a page using PHP/MySQL and populates it as everyone else does with the generic content. Then we store THAT rendered page in a cache (memcache pool as well as a local copy on each server). HOWEVER, there are of course dynamic parts of the page that can't be cached or we'd be making a cached page for every unique user. So things like their ?= $username ?, or maybe parts of the page change based up their membership ?php if ($loggedin == true) { ?, or maybe parts of the page rotate different content (modules if you like). Therefore we are trying to mininimize/compress the cached pages that need to be served by removing all !-- -- and /* */ and // and whitespace and other stuff. When you have this much data to serve that fast, those few characters here and there add up quickly in bandwidth and space. As well as render time for both apache and the client's browser's parser. Dig? -Original Message- From: ma...@behnke.biz [mailto:ma...@behnke.biz] Sent: Friday, May 03, 2013 4:28 AM To: Daevid Vincent; 'php-general General' Subject: RE: [PHP] Need a tool to minimize HTML before storing in memecache But why are you caching uncompiled php code? Daevid Vincent dae...@daevid.com hat am 2. Mai 2013 um 23:21 geschrieben: While that may be true for most users, I see no reason that it should limit or force me to a certain use case given that dynamic pages make up the vast majority of web pages served. Secondly, there are 8 billion options in Tidy to configure it, I would be astonished if they were so short-sighted to not have one to disable converting and to lt; and gt; as they do for all sorts of other things like quotes, ampersands, etc. I just don't know which flag this falls under or what combination of flags I'm setting that is causing this to happen. Barring that little snag, it works like a champ. -Original Message- From: ma...@behnke.biz [mailto:ma...@behnke.biz] Sent: Thursday, May 02, 2013 4:55 AM To: Daevid Vincent; 'php-general General' Subject: RE: [PHP] Need a tool to minimize HTML before storing in memecache This is because tidy is for optimizing HTML, not for optimizing PHP. Daevid Vincent dae...@daevid.com hat am 2. Mai 2013 um 02:20 geschrieben: So I took the time to install Tidy extension and wedge it into my code. Now there is one thing that is killing me and breaking all my pages. This is what I WANT the result to be: link rel=stylesheet type=text/css href=/templates/?= $layout_id ?/css/styles.css / link rel=stylesheet type=text/css href=/templates/?= $layout_id ?/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) / Which then 'renders' out to this normally without Tidy: link rel=stylesheet type=text/css href=/templates/2/css/styles.css / link rel=stylesheet type=text/css href=/templates/2/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) / This is what Tidy does: link rel=stylesheet type=text/css href=/templates/%3C?=%20$layout_id%20?%3E/css/styles.css link rel=stylesheet type=text/css href=/templates/%3C?=%20$layout_id%20?%3E/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) I found ['fix-uri' = false] which gets closer: link rel=stylesheet type=text/css href=/templates/lt;?= $layout_id ?gt;/css/styles.css link rel=stylesheet type=text/css href=/templates/lt;?= $layout_id ?gt;/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) I've tried about every option I can think of. What is the solution to make it stop trying to be smarter than me and converting my and tags?? //See all parameters available here: http://tidy.sourceforge.net/docs/quickref.html $tconfig = array( //'clean' = true, 'hide-comments' = true, 'hide-endtags' = true, 'drop-proprietary-attributes' = true, //'join-classes' = true, //'join-styles' = true, //'quote-marks' = true, 'fix-uri' = false, 'numeric-entities' = true, 'preserve-entities' = true, 'doctype' = 'omit', 'tab-size' = 1, 'wrap' = 0, 'wrap-php' = false, 'char-encoding' = 'raw', 'input-encoding' = 'raw', 'output-encoding' = 'raw', 'newline' = 'LF', 'tidy-mark' = false, 'quiet' = true, 'show-errors' = ($this-_debug ? 6 : 0), 'show-warnings' = $this-_debug, ); From: Joseph Moniz [mailto:joseph.mo...@gmail.com] Sent: Wednesday
RE: [PHP] Need a tool to minimize HTML before storing in memecache
-Original Message- From: Marco Behnke [mailto:ma...@behnke.biz] Sent: Friday, May 03, 2013 12:01 PM To: Daevid Vincent; php php-general@lists.php.net Subject: Re: [PHP] Need a tool to minimize HTML before storing in memecache If you really have that much traffic, then memcache isn't your answer to caching. It is as slow as a fast database. That's not entirely true. You should use APC caching instead. APC will also handle a lot of bytecode caching. We have both. If you want to go with tidy and surf around the php issues you could optimize the single html parts, before glueing everything together. That would require much more work than simply getting and to work. And honestly I've been hacking around Tidy so much at this point with regex to minify the output, that I'm even wondering if Tidy is worth the both anymore. Not sure what else it will give me. Maybe google page speed is worth a look for you too? We have over 1,000 servers in house and also distributed across nodes in various cities and countries. With the loggedin flag, you can save two versions of your rendered, one for loggedin users and for not logged in users. That saves you php code in your template and you can use tidy. And for any other variables you can load the dynamic data after the page load. I gave simplistic examples for the sake of illustration. With tidy, have you tried http://tidy.sourceforge.net/docs/quickref.html#preserve-entities http://tidy.sourceforge.net/docs/quickref.html#fix-uri Yes. See below. I posted all the flags I have tried and I too thought those were the key, but sadly not. Regards, Marco Am 03.05.13 19:40, schrieb Daevid Vincent: Well we get about 30,000 page hits PER SECOND. So we have a template engine that generates a page using PHP/MySQL and populates it as everyone else does with the generic content. Then we store THAT rendered page in a cache (memcache pool as well as a local copy on each server). HOWEVER, there are of course dynamic parts of the page that can't be cached or we'd be making a cached page for every unique user. So things like their ?= $username ?, or maybe parts of the page change based up their membership ?php if ($loggedin == true) { ?, or maybe parts of the page rotate different content (modules if you like). Therefore we are trying to mininimize/compress the cached pages that need to be served by removing all !-- -- and /* */ and // and whitespace and other stuff. When you have this much data to serve that fast, those few characters here and there add up quickly in bandwidth and space. As well as render time for both apache and the client's browser's parser. Dig? -Original Message- From: ma...@behnke.biz [mailto:ma...@behnke.biz] Sent: Friday, May 03, 2013 4:28 AM To: Daevid Vincent; 'php-general General' Subject: RE: [PHP] Need a tool to minimize HTML before storing in memecache But why are you caching uncompiled php code? Daevid Vincent dae...@daevid.com hat am 2. Mai 2013 um 23:21 geschrieben: While that may be true for most users, I see no reason that it should limit or force me to a certain use case given that dynamic pages make up the vast majority of web pages served. Secondly, there are 8 billion options in Tidy to configure it, I would be astonished if they were so short-sighted to not have one to disable converting and to lt; and gt; as they do for all sorts of other things like quotes, ampersands, etc. I just don't know which flag this falls under or what combination of flags I'm setting that is causing this to happen. Barring that little snag, it works like a champ. -Original Message- From: ma...@behnke.biz [mailto:ma...@behnke.biz] Sent: Thursday, May 02, 2013 4:55 AM To: Daevid Vincent; 'php-general General' Subject: RE: [PHP] Need a tool to minimize HTML before storing in memecache This is because tidy is for optimizing HTML, not for optimizing PHP. Daevid Vincent dae...@daevid.com hat am 2. Mai 2013 um 02:20 geschrieben: So I took the time to install Tidy extension and wedge it into my code. Now there is one thing that is killing me and breaking all my pages. This is what I WANT the result to be: link rel=stylesheet type=text/css href=/templates/?= $layout_id ?/css/styles.css / link rel=stylesheet type=text/css href=/templates/?= $layout_id ?/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) / Which then 'renders' out to this normally without Tidy: link rel=stylesheet type=text/css href=/templates/2/css/styles.css / link rel=stylesheet type=text/css href=/templates/2/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) / This is what Tidy does: link rel=stylesheet type=text/css href=/templates/%3C?=%20$layout_id%20?%3E/css
RE: [PHP] Need a tool to minimize HTML before storing in memecache
While that may be true for most users, I see no reason that it should limit or force me to a certain use case given that dynamic pages make up the vast majority of web pages served. Secondly, there are 8 billion options in Tidy to configure it, I would be astonished if they were so short-sighted to not have one to disable converting and to lt; and gt; as they do for all sorts of other things like quotes, ampersands, etc. I just don't know which flag this falls under or what combination of flags I'm setting that is causing this to happen. Barring that little snag, it works like a champ. -Original Message- From: ma...@behnke.biz [mailto:ma...@behnke.biz] Sent: Thursday, May 02, 2013 4:55 AM To: Daevid Vincent; 'php-general General' Subject: RE: [PHP] Need a tool to minimize HTML before storing in memecache This is because tidy is for optimizing HTML, not for optimizing PHP. Daevid Vincent dae...@daevid.com hat am 2. Mai 2013 um 02:20 geschrieben: So I took the time to install Tidy extension and wedge it into my code. Now there is one thing that is killing me and breaking all my pages. This is what I WANT the result to be: link rel=stylesheet type=text/css href=/templates/?= $layout_id ?/css/styles.css / link rel=stylesheet type=text/css href=/templates/?= $layout_id ?/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) / Which then 'renders' out to this normally without Tidy: link rel=stylesheet type=text/css href=/templates/2/css/styles.css / link rel=stylesheet type=text/css href=/templates/2/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) / This is what Tidy does: link rel=stylesheet type=text/css href=/templates/%3C?=%20$layout_id%20?%3E/css/styles.css link rel=stylesheet type=text/css href=/templates/%3C?=%20$layout_id%20?%3E/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) I found ['fix-uri' = false] which gets closer: link rel=stylesheet type=text/css href=/templates/lt;?= $layout_id ?gt;/css/styles.css link rel=stylesheet type=text/css href=/templates/lt;?= $layout_id ?gt;/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) I've tried about every option I can think of. What is the solution to make it stop trying to be smarter than me and converting my and tags?? //See all parameters available here: http://tidy.sourceforge.net/docs/quickref.html $tconfig = array( //'clean' = true, 'hide-comments' = true, 'hide-endtags' = true, 'drop-proprietary-attributes' = true, //'join-classes' = true, //'join-styles' = true, //'quote-marks' = true, 'fix-uri' = false, 'numeric-entities' = true, 'preserve-entities' = true, 'doctype' = 'omit', 'tab-size' = 1, 'wrap' = 0, 'wrap-php' = false, 'char-encoding' = 'raw', 'input-encoding' = 'raw', 'output-encoding' = 'raw', 'newline' = 'LF', 'tidy-mark' = false, 'quiet' = true, 'show-errors' = ($this-_debug ? 6 : 0), 'show-warnings' = $this-_debug, ); From: Joseph Moniz [mailto:joseph.mo...@gmail.com] Sent: Wednesday, April 17, 2013 2:55 PM To: Daevid Vincent Cc: php-general General Subject: Re: [PHP] Need a tool to minimize HTML before storing in memecache http://php.net/manual/en/book.tidy.php - Joseph Moniz (510) 509-0775 | @josephmoniz https://twitter.com/josephmoniz | https://github.com/JosephMoniz GitHub | http://www.linkedin.com/pub/joseph-moniz/13/949/b54/ LinkedIn | Blog http://josephmoniz.github.io/ | CoderWall https://coderwall.com/josephmoniz Wake up early, Stay up late, Change the world On Wed, Apr 17, 2013 at 2:52 PM, Daevid Vincent dae...@daevid.com wrote: We do a lot with caching and storing in memecached as well as local copies so as to not hit the cache pool over the network and we have found some great tools to minimize our javascript and our css, and now we'd like to compress our HTML in these cache slabs. Anyone know of a good tool or even regex magic that I can call from PHP to compress/minimize the giant string web page before I store it in the cache? It's not quite as simple as stripping white space b/c obviously there are spaces between attributes in tags that need to be preserved, but also in the words/text on the page. I could strip out newlines I suppose, but then do I run into any issues in other ways? In any event, it seems like someone would have solved this by now before I go re-inventing the wheel. d. -- Marco Behnke Dipl. Informatiker (FH), SAE Audio Engineer Diploma Zend Certified Engineer PHP 5.3 Tel
RE: [PHP] Need a tool to minimize HTML before storing in memecache
So I took the time to install Tidy extension and wedge it into my code. Now there is one thing that is killing me and breaking all my pages. This is what I WANT the result to be: link rel=stylesheet type=text/css href=/templates/?= $layout_id ?/css/styles.css / link rel=stylesheet type=text/css href=/templates/?= $layout_id ?/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) / Which then 'renders' out to this normally without Tidy: link rel=stylesheet type=text/css href=/templates/2/css/styles.css / link rel=stylesheet type=text/css href=/templates/2/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) / This is what Tidy does: link rel=stylesheet type=text/css href=/templates/%3C?=%20$layout_id%20?%3E/css/styles.css link rel=stylesheet type=text/css href=/templates/%3C?=%20$layout_id%20?%3E/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) I found ['fix-uri' = false] which gets closer: link rel=stylesheet type=text/css href=/templates/lt;?= $layout_id ?gt;/css/styles.css link rel=stylesheet type=text/css href=/templates/lt;?= $layout_id ?gt;/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) I've tried about every option I can think of. What is the solution to make it stop trying to be smarter than me and converting my and tags?? //See all parameters available here: http://tidy.sourceforge.net/docs/quickref.html $tconfig = array( //'clean' = true, 'hide-comments' = true, 'hide-endtags' = true, 'drop-proprietary-attributes' = true, //'join-classes' = true, //'join-styles' = true, //'quote-marks' = true, 'fix-uri' = false, 'numeric-entities' = true, 'preserve-entities' = true, 'doctype' = 'omit', 'tab-size' = 1, 'wrap' = 0, 'wrap-php' = false, 'char-encoding' = 'raw', 'input-encoding' = 'raw', 'output-encoding' = 'raw', 'newline' = 'LF', 'tidy-mark' = false, 'quiet' = true, 'show-errors' = ($this-_debug ? 6 : 0), 'show-warnings' = $this-_debug, ); From: Joseph Moniz [mailto:joseph.mo...@gmail.com] Sent: Wednesday, April 17, 2013 2:55 PM To: Daevid Vincent Cc: php-general General Subject: Re: [PHP] Need a tool to minimize HTML before storing in memecache http://php.net/manual/en/book.tidy.php - Joseph Moniz (510) 509-0775 | @josephmoniz https://twitter.com/josephmoniz | https://github.com/JosephMoniz GitHub | http://www.linkedin.com/pub/joseph-moniz/13/949/b54/ LinkedIn | Blog http://josephmoniz.github.io/ | CoderWall https://coderwall.com/josephmoniz Wake up early, Stay up late, Change the world On Wed, Apr 17, 2013 at 2:52 PM, Daevid Vincent dae...@daevid.com wrote: We do a lot with caching and storing in memecached as well as local copies so as to not hit the cache pool over the network and we have found some great tools to minimize our javascript and our css, and now we'd like to compress our HTML in these cache slabs. Anyone know of a good tool or even regex magic that I can call from PHP to compress/minimize the giant string web page before I store it in the cache? It's not quite as simple as stripping white space b/c obviously there are spaces between attributes in tags that need to be preserved, but also in the words/text on the page. I could strip out newlines I suppose, but then do I run into any issues in other ways? In any event, it seems like someone would have solved this by now before I go re-inventing the wheel. d.
[PHP] Need a tool to minimize HTML before storing in memecache
We do a lot with caching and storing in memecached as well as local copies so as to not hit the cache pool over the network and we have found some great tools to minimize our javascript and our css, and now we'd like to compress our HTML in these cache slabs. Anyone know of a good tool or even regex magic that I can call from PHP to compress/minimize the giant string web page before I store it in the cache? It's not quite as simple as stripping white space b/c obviously there are spaces between attributes in tags that need to be preserved, but also in the words/text on the page. I could strip out newlines I suppose, but then do I run into any issues in other ways? In any event, it seems like someone would have solved this by now before I go re-inventing the wheel. d.
RE: [PHP] Need a tool to minimize HTML before storing in memecache
-Original Message- From: Matijn Woudt [mailto:tijn...@gmail.com] Sent: Wednesday, April 17, 2013 3:11 PM To: Daevid Vincent Cc: PHP List Subject: Re: [PHP] Need a tool to minimize HTML before storing in memecache On Wed, Apr 17, 2013 at 11:52 PM, Daevid Vincent dae...@daevid.com wrote: We do a lot with caching and storing in memecached as well as local copies so as to not hit the cache pool over the network and we have found some great tools to minimize our javascript and our css, and now we'd like to compress our HTML in these cache slabs. Anyone know of a good tool or even regex magic that I can call from PHP to compress/minimize the giant string web page before I store it in the cache? It's not quite as simple as stripping white space b/c obviously there are spaces between attributes in tags that need to be preserved, but also in the words/text on the page. I could strip out newlines I suppose, but then do I run into any issues in other ways? In any event, it seems like someone would have solved this by now before I go re-inventing the wheel. d. How about you just compress it? Gzip, bzip2, etc. Pick your favourite. http://www.php.net/manual/en/refs.compression.php - Matijn Well we already use the gzip compression that is built into Apache since that works in tandem with the client too. http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/ The point of minification is to remove comments, commented sections, optimize the code by removing closing tags when not needed (/p or br/), strip unnecessary white space, etc.. there is more to it than just squeezing bits which is what LZO or GZIP do. They work in conjunction with each other. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ?=$var?
It is the equivalent of ?php echo $var; ? it's just easier to type and read IMHO. For a while people were freaking out that they thought it would be deprecated, but that is not (nor ever will be) the case. -Original Message- From: Larry Martell [mailto:larry.mart...@gmail.com] Sent: Wednesday, April 17, 2013 3:51 PM To: PHP General Subject: [PHP] ?=$var? Continuing in my effort to port an app from PHP version 5.1.6 to 5.3.3, the app uses this construct all over the place when building links: ?=$var? I never could find any documentation for this, but I assumed it was some conditional thing - use $var if it's defined, otherwise use nothing. In 5.1.6 it seems to do just that. But in 5.3.3 I'm not getting the value of $var even when it is defined. Has this construct been deprecated? Is there now some other way to achieve this? -- 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] Compiler for the PHP code
Dear Kevin, please install and use the PECL bcompiler extension. You will need to use the approprate version for your php regards On Tue, Mar 19, 2013 at 11:46 AM, Kevin Peterson qh.res...@gmail.comwrote: My webcode written in PHP and it is running in the interpreted way. My problem is it is not giving the desired performance so want to try the compiler if any. Please suggest if we have aany compiler option available for the PHP code and more important is this new option. -- Tumwijukye Vincent Chief Executive Officer Future Link Technologies Plot 78 Kanjokya Street, P. O. BOX 75408, KAMPALA - UGANDA Tel: +256(0)774638790 Off:+256(0)41531274 Website: www.fl-t.com, www.savingsplus.info
RE: [PHP] Re: Compiler for the PHP code (memecached)
-Original Message- From: Alessandro Pellizzari [mailto:a...@amiran.it] Sent: Tuesday, March 19, 2013 2:06 AM To: php-general@lists.php.net Subject: [PHP] Re: Compiler for the PHP code Il Tue, 19 Mar 2013 08:46:22 +, Kevin Peterson ha scritto: My webcode written in PHP and it is running in the interpreted way. My problem is it is not giving the desired performance so want to try the compiler if any. PHP gets compiled to bytecode on the server before being executed. You can cache the precompiled code with (for example) APC. Unless your code is several thousand lines of code (or your server very slow... 486-slow), the compilation phase is not that long. I think your main problem can be one of: 1- wrong algorithm 2- long waits (database, files, network, etc.) 3- heavy calculations Solutions: 1- find and use a different algorithm 2- Try to parallelize code (with gearman or similar, or via pctnl_fork) 3- rewrite the heavy functions in C, C++ or Go and compile them, then call them via PHP extensions or via gearman/fork. Another thing you can do is store both page renders as well as database results in http://memcached.org/ blobs and pull from those in intelligent ways (you can creatively mix and match live stuff with cached stuff and you can make pages expire in defined hours via your cache class or even a crontab). We also add another layer in that if a blob exists in the memecached but not locally, we save it locally for the next hit. Depending on your hardware though the Gigabit/Fiber might be faster access than a local HD/SSD/RAM disk, so YMMV. We use LAMP and our site gets 30,000 hits per SECOND on two servers and 5 pools. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Joining a team, where no wiki or docs are available
-Original Message- From: AmirBehzad Eslami [mailto:behzad.esl...@gmail.com] Sent: Monday, September 24, 2012 7:05 AM To: PHP General Mailing List Subject: [PHP] Joining a team, where no wiki or docs are available Hi, i'm going to join a mid-size company with a few PHP-driven projects written in procedural PHP, million years old. At the moment, they don't have a wiki or any documentation about their projects. For me, the first challenge in probation period is to understand how their code works. * Considering that there is no wiki or docs, How can I see the Big Picture?* i'm sure this is a common problem for programmers everywhere. What approach do you use in a similar situation? Is there a systematic approach for this? Is there reverse-engineering technique to understand the design of code? Please share your experience and thoughts. -Thanks in advance, Behzad I was in this same situation when I started 2011-03. No wiki. No revision control. No real process. No documentation. They'd push to production by copying files manually. When they wanted to create a new website, they'd clone an existing one and start modifying -- no shared libraries (so they had 50 versions of the same dbconnection.class.php but all just slightly different since that is also where they housed the configuration user/pass/etc.)!! It was a clu$terfsck. Take a day or two to go through every menu item and just see how the thing works from a user POV. You don't have to memorize it, just be familiar with concepts, vocabulary, paths, etc. First thing I did was install Trac http://trac.edgewall.org/ And of course Subversion. I personally recommend the 1.6 branch and not the newer 1.7 that uses sqlite. That version seems to always corrupt, especially on the clients (like in TortoiseSVN). http://subversion.apache.org/ I would use something to visually map out the database. If it's using MySQL, there are free tools like MySQL Workbench. But if they don't use InnoDB tables, it can get painful to draw the lines if it's a large DB. http://www.mysql.com/products/workbench/ I then started to go through code and use PHPDoc for every major function or method, especially in classes or include files where the meaty stuff happens, or very complex portions. I didn't bother with every get_* or set_* unless there was something obscure about them. Although, over a year later, and we have pretty much filled them all in now as the other devs started helping once they saw how easy it is to do a few as you encounter them in your daily coding, and how awesome that integrates with PDT or Zend Studio (amongst other IDEs). We didn't generate an actual PHPDoc Web version, there's really no need. The IDE shows you the important stuff anyways. We're pretty diligent about keeping these PHPDoc comment blocks updated now. http://www.zend.com/en/products/studio/ I then started the long tedious process of merging our various different sites to implement shared libraries (database connections, memecache, various objects, etc.). If you have only one project, then this is less of an issue, but if you have 1 vhost or something then you'll want to do this. All the while I documented useful tips, tricks, explanations, etc. in the Wiki. Referencing source code (which is of course committed at this point). Trac rules in that respect. Xdebug will give you vastly better call stack and var_dump() alone. I don't use the breakpoint stuff myself, but that is another benefit perhaps. http://xdebug.org/ And for the love of [insert deity of your choice here] not EVERYTHING has to be OOP. Use the best tool for the job!! Nothing pisses me off more than having to instantiate a new class just to do some simple method that a standard function would do. If you want to be organized, use static methods then where appropriate, but don't avoid functions just because some book told you that OOP is the king $hit. d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Joining a team, where no wiki or docs are available
That is a good point. We do not do unit tests here. Nothing against them, it’s just a bit overkill for our needs. We build lots of websites, not one massive SaaS. But I’m not saying do not use OOP. I’m just saying not everything has to be OOP. It’s a subtle but significant difference. We have OOP classes for our database connection (and of course the helper routines), memecache access/purging/etc., and then objects for actors, movies, scenes, search results, HTML templates, email, tickets, etc… again, use the right tool for the job. When all you have is a hammer, everything is a nail. Build a toolbox. ;-) From: AmirBehzad Eslami [mailto:behzad.esl...@gmail.com] Sent: Monday, September 24, 2012 12:47 PM To: Daevid Vincent Cc: PHP General Mailing List Subject: Re: [PHP] Joining a team, where no wiki or docs are available Wow. David. That was a great help with every detail ! Thanks for sharing that with us. One side question: Without OOP, how do you handle Unit Tests? Do you know a Testing framework for procedural code?
RE: [PHP] Re: Programmers and developers needed
-Original Message- From: Matijn Woudt [mailto:tijn...@gmail.com] You're missing the most important aspect of social networks.. Advertising. Please tell me that is said sarcastically. Advertising is the cancer of the internet. There was a time when there weren't ad banners, interstitials, pop-ups, pop-unders, spam, and all the other bullshit you have to sift through on a daily basis. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Programmers and developers needed -- TiVo booooo!
-Original Message- From: Paul M Foster [mailto:pa...@quillandmouse.com] I bought TiVo partially so I could skip ads. I've revelled in it every day since. I can watch an hour-long program in 47 minutes. (Though this is a sad commentary on television and cable content providers.) Not to tangent too far here, but I'm about ready to cancel my TiVo. I've been with them since 1999. It infuriates me to no end that they too are now shoving their stupid ad banners into the GUI menu. I've even seen commercials that had the thumbs up icon in the upper corner to learn more. I see the same Bounty Paper Towels logo in my TiVo GUI everywhere. Don't get me started on their made-for-dumb-users crapy GUI and the unbearably slow navigation. UGHHGHGHH!!! I pay these bastards $15/mo basically for a TV guide. Because let's face it, without the guide, the DVR is pretty useless. I have a Windows7 MCE in my living room with the Ceton InfiniTV PCIe board and this is the best PVR/DVR I have ever seen/used (and I tried many from Myth, XBMC, MCE2005, others that are now defunct). WELL worth the initial cost to build. Works flawlessly. 4 HD streams (per card)! No monthly fees. Full HTPC experience with plugins even (weather, RSS, movies, etc.) http://cetoncorp.com/products/infinitv/ I was just approved to be on the beta testing team for the Echo due out by year's end. I should have my testing box by month's end. Once that happens and this thing works as I think it will (given the awesomeness of their other products), the TiVo Premier in my bedroom will make a great backstop for my AR-15 .223 rounds (and I will enjoy pumping that thing full of lead) http://cetoncorp.com/products/echo/ Yes, ads are Evil(tm). Amen. And the punishment for mass spammers should be death. I am not even joking. It would stop quicker than a failed Nigerian phishing scam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Creating drop-down menus - use AJAX and jQuery
Hold on there fireball. * jQuery for production (minified) is a scant 32k. http://jquery.com/ LOL That's like a TCP/IP packet. I bet your images are bigger than 32k. * Unlike stupid PHP frameworks (which everyone knows I detest) - JS frameworks are cached by the browser so there is no download on every page - JS frameworks take all the bullshit browser discrepancies out of your way * once you start using jQuery, you will 3 it and use it for many other tasks you'd beat your head against a wall in plain old JS to do. * All the plugins to add extra functionality make it that much more enticing I've not tried YUI or Google's JS framework, but I can tell you that jQuery pretty much rocks harder than Pantera and you're doing yourself, and your customers a disservice if you're not using it. We get nearly 30,000 hits per second (yes PER SECOND) and have no problems using jQuery and many plugins and various .css files We use this too to cram all the .js and .css into one 'package': http://developer.yahoo.com/yui/compressor/ d -Original Message- From: Paul M Foster [mailto:pa...@quillandmouse.com] Sent: Tuesday, July 17, 2012 1:59 PM To: php-general@lists.php.net Subject: Re: [PHP] Creating drop-down menus On Wed, Jul 18, 2012 at 08:45:34AM +1200, James Newman wrote: Just to put my 2cents in, you might want to try jQuery if you're going to go down the AJAX road. JQuery is a LOT of code to include if you're just going to do an AJAX call or two. There are examples of doing straight AJAX with Javascript on the 'Net. Once you work through them, you find that there's a static part that you can include in all the files you want to make AJAX calls. And then there's the part that deals directly with the data you get back from whatever PHP or other script is feeding you data from outside the website. That's the part that needs custom work. I *hate* Javascript, but I managed to figure it out. Another point: I'm not sure if it's the same for other people. I'm on a crappy little computer running Linux. I've got a little CPU meter in my taskbar. And nothing jacks that meter up like Javascript. I don't know why, but Javascript just devours CPU on my computer. The more javascript, the worse. And like I said, JQuery is a LOT of code. This is one of the reasons I tend to code things in PHP instead of Javascript. Paul -- Paul M. Foster http://noferblatz.com http://quillandmouse.com -- 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] Creating drop-down menus
AJAX. Your page calls a PHP 'ajax' routine that pulls the data, sends it back as a JS array, and you re-populate the second select box. Welcome to the year 2000. Using frameworks like jQuery, this is pretty trivial these days. You're not trading any security since the PHP gets whatever parameters and checks whatever $_SESSION or other authentication and only sends back whatever data is needed. You can add some caching (memcached or whatever else) to make subsequent calls lightning fast. -Original Message- From: Ramiro Barrantes [mailto:ram...@precisionbioassay.com] Sent: Monday, July 16, 2012 1:17 PM To: php-general@lists.php.net Subject: [PHP] Creating drop-down menus Hello, I am making an application using PHP/Javascript/mysql and had a question. Sometimes I need to use javascript to fill a drop down box based on the value of a previous drop down box. However, the information to fill the latter is stored in mysql and can be a lot, what I have been doing is that, using PHP, I create hidden fields with all the possible information that might be needed to fill the second drop down. For example, the user chooses a bank from a drop down, and then a list of clients is displayed on the following drop down. I use PHP to read all clients from all the banks and put that as hidden fields on the html page. It is very cumbersome. I do not want to read the database (which changes dynamically) from javascript directly due to confidentiality and because a lot of care has been taken to create the appropriate queries with checks and protect misuse of the information using PHP. My questions are: 1) Do people just normally use hidden fields to store possible information to fill the drop downs? 2) any suggestions? Thanks in advance, Ramiro -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Entry point of an MVC framework
-Original Message- From: Simon Dániel [mailto:simondan...@gmail.com] Sent: Thursday, July 12, 2012 1:21 PM Subject: [PHP] Entry point of an MVC framework I have started to develop a simple MVC framework. Yeah! Just what PHP needs, another MVC framework NOT. Why are you re-inventing the wheel? Personally I *hate* frameworks with a passion, but if you're going to use one, then why not just build with one that is already out there and well supported. http://www.phpframeworks.com/ to start with. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Is there a way to customize the 'Username' and 'Password' strings in a 401 auth dialog box?
Is there a way to customize the 'Username' and 'Password' strings in a 401 auth dialog box? I want to change mine to say Webmaster ID and Authentication Key. http://php.net/manual/en/features.http-auth.php
[PHP] If PHP Were British
http://www.addedbytes.com/blog/if-php-were-british/
RE: [PHP] If PHP Were British
-Original Message- From: paras...@gmail.com [mailto:paras...@gmail.com] On Behalf Of Daniel Brown Sent: Friday, June 22, 2012 4:03 PM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] If PHP Were British On Fri, Jun 22, 2012 at 5:07 PM, Daevid Vincent dae...@daevid.com wrote: http://www.addedbytes.com/blog/if-php-were-british/ Eh, what the hell, it's Friday http://links.parasane.net/eea4 HA! NICE! Thanks for the nod too! :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] why is (intval('444-44444') == '444-44444') EQUAL??!
Huh? Why is this equal??! php $id = '444-4'; php var_dump($id, intval($id)); string(9) 444-4 int(444) php if (intval($id) == $id) echo 'equal'; else echo 'not equal'; equal or in other words: php if (intval('444-4') == '444-4') echo 'equal'; else echo 'not equal'; equal I would expect PHP to be evaluating string 444-4 against integer 444 (or string either way) however, just for giggles, using === works... php if ($id === intval($id)) echo 'equal'; else echo 'not equal'; not equal -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP: a fractal of bad design
http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ Can't say he doesn't have some good points, but he sure goes about it in a dickish way.
[PHP] set_error_handler() only triggering every Nth time
Resending since I didn't get a single reply. Maybe it got lost? -Original Message- Sent: Tuesday, March 13, 2012 5:58 PM I am implementing a custom error handler and started noticing some bizarre behavior. Every Nth time I refresh the page, I see the error/output. In my 'includes/common.inc.php' the key things are these: set_error_handler('php_error_handler'); function php_error_handler($errno, $errstr, ...) { //does some stuff //calls php_custom_error_log() } function php_custom_error_log() { echo php_custom_error_log : .date('H:i:s'); if ($error = error_get_last()) { var_dump(LOG_LEVEL, $error); //does more stuff } My test page: ?php define('LOG_LEVEL', E_ALL ^ E_NOTICE); error_reporting(LOG_LEVEL); ini_set('display_errors','On'); define('VM', true); define('DEVELOPMENT', false); ini_set('xdebug.var_display_max_children', 1000 ); ini_set('xdebug.var_display_max_depth', 5 ); require_once 'includes/common.inc.php'; ## BEGIN TEST # foreach($empty as $k) echo $k; ? For those astute observers, you'll note that $empty is not an array and therefore I expect an error message (well warning) ( ! ) Warning: Invalid argument supplied for foreach() in /usr/home/vz/examples.videosz.com/error_handler_tests.php on line 20 Call Stack # TimeMemory FunctionLocation 1 0.0005 663616 {main}( ) ../error_handler_tests.php:0 As I simply click 'refresh' on the browser I noticed that it was only periodically working. I then deduced that it was directly related to the number of apache threads. So if I had 15 then it would work every 15th refresh: developer@vm:/usr/local/etc/apache22$ ps aux | grep httpd (standard input):39:root 15855 0.0 2.0 204156 20292 ?? Ss 28Feb12 1:33.48 /usr/local/sbin/httpd -k start (standard input):48:www 89522 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):49:www 89523 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):50:www 89524 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):51:www 89525 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):52:www 89527 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):53:www 89528 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):54:www 89529 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):55:www 89530 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):56:www 89531 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):57:www 89532 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):58:www 89533 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):59:www 89534 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):60:www 89535 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):61:www 89563 0.0 2.1 206204 21700 ?? I 8:17PM 0:00.10 /usr/local/sbin/httpd -k start (standard input):62:www 89578 0.0 2.0 204156 20332 ?? I 8:22PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):74:developer 89587 0.0 0.1 9092 1196 1 S+8:30PM 0:00.01 grep -inH --color httpd 124 IfModule prefork.c 125 StartServers 15 126 MinSpareServers 15 127 MaxSpareServers 20 128 ServerLimit 50 129 MaxClients50 130 MaxRequestsPerChild 15 131 KeepAlive Off 132 /IfModule Just to check and the time is updating each press and every 15th try I'd get this: php_custom_error_log : 19:54:20 int 30711 array 'type' = int 8192 'message' = string 'Directive 'register_globals' is deprecated in PHP 5.3 and greater' (length=65) 'file' = string 'Unknown' (length=7) 'line' = int 0 When I'd expect to see a message every time (with a new timestamp). Then I REALLY looked at the 'message' part. register_globals. WTF? That isn't the error I expected. Hmmm.. what happens if I move the second function inline to the first... BAM! EVERY TIME it works perfectly. So WTFF??! Why does moving it inline make any difference? All I suspect is the $error = error_get_last() part. For some reason that isn't consistent. And the other strange thing is that it's giving me erroneous error messages
[PHP] set_error_handler() only triggering every Nth time
I am implementing a custom error handler and started noticing some bizarre behavior. Every Nth time I refresh the page, I see the error/output. In my 'includes/common.inc.php' the key things are these: set_error_handler('php_error_handler'); function php_error_handler($errno, $errstr, ...) { //does some stuff //calls php_custom_error_log() } function php_custom_error_log() { echo php_custom_error_log : .date('H:i:s'); if ($error = error_get_last()) { var_dump(LOG_LEVEL, $error); //does more stuff } My test page: ?php define('LOG_LEVEL', E_ALL ^ E_NOTICE); error_reporting(LOG_LEVEL); ini_set('display_errors','On'); define('VM', true); define('DEVELOPMENT', false); ini_set('xdebug.var_display_max_children', 1000 ); ini_set('xdebug.var_display_max_depth', 5 ); require_once 'includes/common.inc.php'; ## BEGIN TEST # foreach($empty as $k) echo $k; ? For those astute observers, you'll note that $empty is not an array and therefore I expect an error message (well warning) ( ! ) Warning: Invalid argument supplied for foreach() in /usr/home/vz/examples.videosz.com/error_handler_tests.php on line 20 Call Stack # TimeMemory FunctionLocation 1 0.0005 663616 {main}( ) ../error_handler_tests.php:0 As I simply click 'refresh' on the browser I noticed that it was only periodically working. I then deduced that it was directly related to the number of apache threads. So if I had 15 then it would work every 15th refresh: developer@vm:/usr/local/etc/apache22$ ps aux | grep httpd (standard input):39:root 15855 0.0 2.0 204156 20292 ?? Ss 28Feb12 1:33.48 /usr/local/sbin/httpd -k start (standard input):48:www 89522 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):49:www 89523 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):50:www 89524 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):51:www 89525 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):52:www 89527 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):53:www 89528 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):54:www 89529 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):55:www 89530 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):56:www 89531 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):57:www 89532 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):58:www 89533 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):59:www 89534 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):60:www 89535 0.0 2.0 204156 20332 ?? I 8:03PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):61:www 89563 0.0 2.1 206204 21700 ?? I 8:17PM 0:00.10 /usr/local/sbin/httpd -k start (standard input):62:www 89578 0.0 2.0 204156 20332 ?? I 8:22PM 0:00.01 /usr/local/sbin/httpd -k start (standard input):74:developer 89587 0.0 0.1 9092 1196 1 S+8:30PM 0:00.01 grep -inH --color httpd 124 IfModule prefork.c 125 StartServers 15 126 MinSpareServers 15 127 MaxSpareServers 20 128 ServerLimit 50 129 MaxClients50 130 MaxRequestsPerChild 15 131 KeepAlive Off 132 /IfModule Just to check and the time is updating each press and every 15th try I'd get this: php_custom_error_log : 19:54:20 int 30711 array 'type' = int 8192 'message' = string 'Directive 'register_globals' is deprecated in PHP 5.3 and greater' (length=65) 'file' = string 'Unknown' (length=7) 'line' = int 0 When I'd expect to see a message every time (with a new timestamp). Then I REALLY looked at the 'message' part. register_globals. WTF? That isn't the error I expected. Hmmm.. what happens if I move the second function inline to the first... BAM! EVERY TIME it works perfectly. So WTFF??! Why does moving it inline make any difference? All I suspect is the $error = error_get_last() part. For some reason that isn't consistent. And the other strange thing is that it's giving me erroneous error messages (well, we do have register_globals on, but that's not the error I was expecting). Then I did another test replacing the foreach()
[PHP] How do I enable more useful PHP error logging?
My question is, is there a way to enable some PHP configuration that would output more verbose information, such as a backtrace or the URL attempted? In our PHP error log, we have the usual semi-useful information. However this is only a partial story as it's hard to re-create the URL that caused the error. In the first Actor example, yeah actor_id 2206 doesn't exist and so now I have put a try/catch on all pages that have new Actor($actor_id) but it doesn't tell me WHY this is happening. How did someone get to this point? I doubt they just randomly picked '2206' which happens to be one of only a handful of actually missing actors out of 100k. Sure I guess it could be a bot that sequentially tried them all, but this is not likely since we have SEO style URLs and so we re-map an actor name back to the ID. So the bot would have to try NAMEs not IDs. This means we must have some link somewhere that points to this. Same with the common foreach() warnings below. Yeah, the array being passed is empty/null. Sure I can check the array before doing the foreach() or even @foreach() but that doesn't tell me the root cause. What video are they trying to access that has no scenes or invalid actors? We do NOT have apache logging turned on as we get 30,000 hits per second and it would be too expensive. I only care about PHP errors like this. And the apache error log (which we do have enabled) doesn't have useful info related to these kinds of issues as they're really not apache's problem. That log only deals with missing files/images/pages/etc. [28-Feb-2012 13:43:19 UTC] PHP Fatal error: Uncaught exception 'ObjectNotFound' with message 'There is no such object Actor [2206].' in /home/SHARED/classes/base.class.php:103 Stack trace: #0 /home/SHARED/classes/actor.class.php(61): Base-load_from_sql() #1 /home/m.videosz.com/browse_scenes.php(89): Actor-__construct(2206) #2 {main} thrown in /home/SHARED/classes/base.class.php on line 103 [28-Feb-2012 10:54:01 UTC] PHP Warning: Invalid argument supplied for foreach() in /home/m.dev.com/scene.php on line 138 [28-Feb-2012 07:22:50 UTC] PHP Warning: Invalid argument supplied for foreach() in /home/SHARED/classes/scene.class.php on line 423 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How do I enable more useful PHP error logging?
-Original Message- From: Stuart Dallas [mailto:stu...@3ft9.com] Seriously? Errors like this should not be getting anywhere near your production servers. This is especially true if you're really getting 30k hits/s. Don't get me started. I joined here almost a year ago. They didn't even have a RCS or Wiki at the time. Nothing was OOP. There were no PHPDoc or even comments in the code. They used to make each site by copying an existing one and modifying it (ie. no shared libraries or resources). I could go on and on. Suffice it to say we've made HUGE leaps and bounds (thanks to me!), but there is only 3 of us developers here and no official test person let alone a test team. It is what it is. I'm doing the best I can with the limited resources available to me. And let me tell you a little secret, when you get to that scale, you see all kinds of errors you don't see on your VM or even with a test team. DB connections go away. Funny things happen to memcache. Concurrency issues arise. Web bots and search engines rape, pillage and ravage your site in ways that make you feel dirty. So yeah, you do hit weird situations and cases you can't possibly test for, but show up in error logs. For a commercial, zero-hassle solution I can't recommend http://newrelic.com/ highly enough. Simple installation followed by highly detailed reports with zero issues (so far). They do a free trial of all the pro features so you can see if it gets you what you need. And no, I don't work for them, I just think they've built a freakin' awesome product that's invaluable when diagnosing issues that only occur in production. I've never used it on a site with that level of traffic, and I'm sure it won't be a problem, but you may want to only deploy it to a fraction of your infrastructure. A quick look at that product seems interesting, but not what I really need. We have a ton of monitoring solutions in place to get metrics and performance data. I just need a good 'hook' to get details when errors occur. If you want a homemade solution, the uncaught exceptions are easily dealt with... CATCH THEM, do something useful with them, and then die gracefully. Rocket science this ain't! Thanks captain obvious. :) I can do that (and did do that), but again, at these scales, all the text-book code you think you know starts to go out the window. Frameworks break down. RDBMS topple over. You have to write things creatively, leanly (and sometimes error on the side of 'assume something is there' rather than 'assume the worst' or your code spends too much time checking the edge cases). Hit it and quit it! Get in. Get out. I can't put try/catch around everything everywhere, it's just not efficient or practical. Even the SQL queries we write are 'wide' and we pull in as much logical stuff as we can in one DB call, get it into a memcache slab and then pull it out of there over and over, rather than surgical queries to get small chunks of data which would murder mySQL. Part of the reason I took this job is exactly because of these challenges and I've learned an incredible amount here (I've also had to wash the guilt off of me some nights, as some code I've written goes against everything I was taught and thought I knew for the past decade -- but it works and works well -- it just FEELS wrong). We do a lot of things that would make my college professors cringe. THAT is the difference between the REAL world and the LAB. ;-) See the set_exception_handler function for an easy way to set up a global function to catch uncaught exceptions if you don't have a limited number of entry points. You can similarly catch the warnings using the set_error_handler function, tho be aware that this won't be triggered for fatal errors. And this is the meat of the solution. Thanks! I'll look into these handlers and see if I can inject it into someplace useful. I have high hopes for this now. But seriously... a minimal level of structured testing would prevent issues like this being deployed to your production servers. Sure, instrument to help resolve these issues now, but if I were you I'd be putting a lot of effort into improving your development process. Contact me off-list if you'd like to talk about this in more detail. See above. I have begged for even a single dedicated tester. I have offered to sacrifice the open req I had for a junior developer to get a tester. That resulted in them taking away the req because clearly I didn't need the developer then and we can just test it ourselves. You're preaching to the choir my friend. I've been doing this for 15+ years at various companies. ;-) d. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Where did my comment go related to lower/upper bounds for any number and offset?
Hey. To anyone that works on the php.net site. I posted this comment: http://www.php.net/manual/en/language.operators.bitwise.php#107617 And I saw it there shortly after and even sent that link to some colleagues. Now it's gone on every mirror too. WTF?? :-( It certainly was relevant as it used and ~. This is what it said basically (although this is a much longer version/explanation. The note post only had the code function and results). We've started to convert more of our queries to a wide mode and take even more advantage of memcache instead of a thin mode where we hit the DB (and store in memcache too) for each scene. The idea being that if we make the queries pull more data than needed (in an intelligent way of course) then we hit the DB less and memcache more. This works great with the concept of a DVD vs SCENE as one is macro and one is micro. I used some bitwise operations to figure out a lower/upper number for any given number (and offset). /** * Get the upper and lower boundaries for any given number and 2^n offset (other offsets give bizarre results) * * @access public * @return array * @param integer $number * @param integer $offset (32) must be a 2^n value [8, 16, 32, 64, 128, ...) * @author Daevid Vincent * @date 2012-02-21 */ function boundaries_ul($number, $offset=32) { if ($offset 8) return false; //nothing smaller than this makes practical sense if (($offset ($offset - 1)) != 0) return false; //not a 2^n $offset = $offset - 1; //zero out least significant bits. //For example if $offset = 32, then the least 5 bits [16 8 4 2 1] == 31 == 0xFFE0 $lowerbound = $number ~$offset; $upperbound = $lowerbound + $offset; return array('lower_bound'=$lowerbound, 'upper_bound'=$upperbound); } for ($i = 0; $i 20; $i++) { debug_print($i, 'forloop $i decimal'); $b = boundaries_ul($i, 8); var_dump($b); echo hr\n; } ? forloop $i decimal = 3 array 'lower_bound' = int 0 'upper_bound' = int 7 forloop $i decimal = 4 array 'lower_bound' = int 0 'upper_bound' = int 7 forloop $i decimal = 5 array 'lower_bound' = int 0 'upper_bound' = int 7 ... forloop $i decimal = 12 array 'lower_bound' = int 8 'upper_bound' = int 15 forloop $i decimal = 13 array 'lower_bound' = int 8 'upper_bound' = int 15 forloop $i decimal = 14 array 'lower_bound' = int 8 'upper_bound' = int 15 In the get_like()/get_dislike(), we pull in both at the same time from the same table, which is great. But we can only pull in by scene_id and not a whole dvd_id (since we don't have the dvd_id in that table) as many of the other queries I'm converting. That got me thinking of how can I get more juice for the squeeze. Given that most scenes (if not all) are sequential that is a clue. We use the md5($sql) as the hash for memcache so that's why this works, since the same 128 scene_id's will all result in the same $sql query string (thanks to upper/lower bounds) and therefore the same hash key is pulled. Knowing these 'constants', I then fabricate a query for say scene_id = 21269 var_dump(boundaries_ul(21269, 128)); Which would look something like this: SELECT `scene_id`, `like`, `dislike` FROM `scene_likes` WHERE `scene_id` BETWEEN 21248 AND 21375; The MD5 hash = 801206aca6ee8b908095161db8d77585 . Which is now the same for ANY of 128 scenes from 21248 through 21375 and therefore all in the same memcache slab. Now in code, pull up to 128 rows at a time (since a memcache slab can be upto 1 MB, this should easily fit) $b = boundaries_ul($this-id, 128); $result = $con-fetch_query_pair(SELECT `scene_id`, CONCAT(`like`,'|',`dislike`) FROM `scene_likes` WHERE `scene_id` BETWEEN .$b['lower_bound']. AND .$b['upper_bound']); list($this-like, $this-dislike) = explode('|', $result[$this-id]); And with a little clever PHP slicing and dicing, I have an index right to the scene_id and the dis/likes. fetch_query_pair() does just like it sounds, it returns a hash/array where the $col[0] is the key and $col[1] is the value since this is such a common thing to do. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Auto CRUD Generator Xataface
-Original Message- Search Google for Xataface. It's a full frontend which dynamically changes with database structure changes. http://xataface.com/videos is broken and therefore we can't view the demo, and nothing pisses me off more than a site that doesn't have a simple contact email link! UGH! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Auto CRUD Generator Xataface
-Original Message- From: Matijn Woudt [mailto:tijn...@gmail.com] Sent: Tuesday, November 29, 2011 12:48 PM To: Daevid Vincent Cc: php-general-h...@lists.php.net; php-general@lists.php.net Subject: Re: [PHP] Auto CRUD Generator Xataface On Tue, Nov 29, 2011 at 9:44 PM, Daevid Vincent dae...@daevid.com wrote: -Original Message- Search Google for Xataface. It's a full frontend which dynamically changes with database structure changes. http://xataface.com/videos is broken and therefore we can't view the demo, and nothing pisses me off more than a site that doesn't have a simple contact email link! UGH! I think your PC is broken.. I can watch the videos just fine ;) I tried it in FF 3.6.24 as well as Chrome 15.0.874.121 m (is that really necessary Google?!) and lastly IE 8.0.7601.17514 (is that really necessary Micro$oft?!). All on Win7 64-bit burley-ass Dell PC. I code in PHP all day long and have no troubles with other websites. Not even other pages on THAT web site. That particular tab / page however only shows the logo top left, search top right, and then these in the tabs: Home Forum Documentation Videos a href=http:// And the rest of the page is white. Garbage. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dennis Ritchie, Father of Unix and C programming language, dead at 70
#include stdio.h int main() { printf(R.I.P. Dennis Ritchie: 1941-2011\n); return 0; } http://www.networkworld.com/news/2011/101311-ritchie-251936.html
[PHP] Episode 2 - All The Cool Kids Use Ruby
http://www.youtube.com/watch?v=5GpOfwbFRcs LOLercopter
RE: [PHP] dev to production server
-Original Message- From: Alex Nikitin [mailto:niks...@gmail.com] Sent: Wednesday, September 07, 2011 8:47 AM To: Chris Stinemetz Cc: PHP General Subject: Re: [PHP] dev to production server If you have to ask these questions, i don't think you should be the person to do it, i'm sorry. [snip] or tell you that you shouldn't do it, infact you should do it, its a lot of fun and great perplexing headache for a while, all i'm trying to say is that you should think about either buying a production environment, or you should really start learning yourself some advanced OS and lots of layer 7... Now there's a contradiction. ;-) Anyways, I do agree with Alex though. Setup and maintenance of a five nines server is non-trivial. You might look into one of the cheap hosting services that use VMs to start with. If you out-grow that, it's pretty easy to migrate your VM to iron. A buddy of mine just joined http://www.linode.com and seems to really like it. Having said that, I would STRONGLY suggest you ditch the whole XAMP, WAMP, MAMP, WTF? they call it these days. Setup VirtualBox (it's free and cross platform). Then setup a VM to be as close to EXACTLY as your production environment as possible (sans hardware specs of course). I mean, same distro, same tools, same versions, same configs, same directory structures. Develop on that. Setup a repository (subversion is easy, well supported and battle tested). Then just do an export from SVN to your PROD box. I have some code snippets that you may find useful here: http://daevid.com/content/examples/snippets.php (And the first person that gives me grief that the page doesn't work in some obscure browser like Safari or something I will bitch-slap. I *know* this. I don't CARE. This is what happens when you use a Framework - and why I have such distain for them. Ceiton went (.)(.) up and so now I'm stuck with minified code in German no less. Use Firefox or IE, or change your user-agent string to trick the page if you insist on using Chrome/Safari/Opera/etc. or don't go to the page at all, it's no sweat off my ) So I digress... back on task... You also should setup a test VM too. So deploy from DEV to TEST first, let someone (preferably besides yourself) hammer away at that, and once you feel it's stable -- in a few days or week -- push to PROD. You have to let the code 'bake' on test to make sure there are no regression bugs or new bugs. I work for a company now where the CTO (by default since it's his company ;-) ) constantly pushes to PROD too early IMHO. It's bitten us more than once. He's so eager to get the new features in front of customers, he doesn't see the potential damage it's doing to the reputation. Granted our customers are pretty forgiving, but still, I would prefer to see a longer DEV-TEST-PROD cycle... d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Code should be selv-maintaining!
LOLercopter! -Original Message- From: David Harkness [mailto:davi...@highgearmedia.com] Sent: Tuesday, August 30, 2011 12:57 PM To: Robert Cummings Cc: rquadl...@gmail.com; Tedd Sperling; php-general@lists.php.net Subject: Re: [PHP] Code should be selv-maintaining! I don't always use braces, but when I do I use Compact Control Readability style. Stay coding, my friends. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] regex or 'tidy' script to fix broken ? tags and introspection of variables
-Original Message- From: Camilo Sperberg [mailto:unrea...@gmail.com] Sent: Tuesday, August 09, 2011 5:27 PM For the first one, it may be that zend studio does have an internal script to do the job. Check the general preferences tab, template stuff. Nope. Nothing there. Those templates are for when you create new blurbs of code, not modifying existing code. There is a formatter however, sadly it doesn't have an option to force these (you'd think that would be the perfect place to do this too huh.) In fact, I posted this here: http://forums.zend.com/viewtopic.php?f=59t=19173#p59348 Please note that ?= is also valid and should be replaced to ?php echo instead. Yeah, I don't like that style. I prefer the ?= $foo ? version. It's shorter, cleaner and easier to read. Many people mistakenly think that short version is going to be deprecated away. It is not. The PHP Devs have already clarified only the ? version is, not this one. http://www.php.net/manual/en/ini.core.php#ini.short-open-tag Also the short if version 1 == 1 ? True : false should be replaced if i'm correct. You are not. ;-) The Ternary operator statement would never go away. It is a standard comparison operator in pretty much any language and would be completely stupid of the PHP Devs to deviate that far from the norm. http://php.net/manual/en/language.operators.comparison.php Plus I love that operator and use it quite frequently. However, I use it like this just for clarity: echo your result is .((1 == 1) ? 'true' : 'false').'br'; Second question: zend studio displays all variables used by a script by clicking the arrow next to te file name. I've used ZS for 4+ years now, and comicaly have never even used those little down arrows next to a file. HAHAH! Good to know. Although it is a little strange as they seem to only be where you use a = assignment. It doesn't know about - or other instances of that variable (like if you echo it or something). But still could prove useful. If you want to display it in runtime, you can: print_r($GLOBALS); Whoa nelly! That prints out WAAY too much information ;-) But thanks. Not sure why I didn't think of that one. Maybe because at one time I did use it, got sensory overload from the amount of data it spews to the page, and then blocked it out of my mind for future use. :) ÐÆ5ÏÐ There are only 11 types of people in this world. Those that think binary jokes are funny, those that don't, and those that don't know binary. -- Sent from my iPhone 5 Beta [Confidential use only] On 09-08-2011, at 19:40, Daevid Vincent dae...@daevid.com wrote: I've inherited a bunch of code and the previous developers have done two things that are really bugging me and I want to clean up. [a] They use short-tag ? instead of ?php. Anyone have some good search/replace style Regex (ideally for ZendStudio/Eclipse) that will run through all the files in the project and fix those? There are lots of cases to account for such as a space after the ? or nospace or a newline or even other text (which are all valid cases). [b] The other thing they do use use register_globals in the php.ini file. Is there a good way to see all the variables that a page uses? Something I can print at the bottom of the page on my dev box - ideally with enough introspection to know where that variable originated from, and then I can start converting things to $_GET, $_POST, $_SESSION, $_COOKIE, etc. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regex or 'tidy' script to fix broken ? tags and introspection of variables
I've inherited a bunch of code and the previous developers have done two things that are really bugging me and I want to clean up. [a] They use short-tag ? instead of ?php. Anyone have some good search/replace style Regex (ideally for ZendStudio/Eclipse) that will run through all the files in the project and fix those? There are lots of cases to account for such as a space after the ? or nospace or a newline or even other text (which are all valid cases). [b] The other thing they do use use register_globals in the php.ini file. Is there a good way to see all the variables that a page uses? Something I can print at the bottom of the page on my dev box - ideally with enough introspection to know where that variable originated from, and then I can start converting things to $_GET, $_POST, $_SESSION, $_COOKIE, etc.
[PHP] How do I enable $_SERVER['HTTP_X_WAP_PROFILE'] or $_SERVER['HTTP_PROFILE']
I'm working on a mobile site and from the various searches and reading (and even code fragments I've inherited for the project), they make reference to: $_SERVER['HTTP_X_WAP_PROFILE'] and a fallback $_SERVER['HTTP_PROFILE'] However, when I hit a phpinfo(); page using both an Android MyTouch 3G (2.2) and an Apple iPhone 3G, there are nothing even close to those. All of the 'HTTP_X_*' headers are absent and there is no HTTP_PROFILE either. http://www.dpinyc.com/literature/resources/code-bank/php-lightweight-device- detection/ http://mobiforge.com/developing/blog/useful-x-headers http://blog.svnlabs.com/tag/_serverhttp_x_wap_profile/ Do I need to enable something in Apache or PHP?? PHP Version 5.3.6 Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans and $ httpd -v Server version: Apache/2.2.17 (FreeBSD) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] is_null() and is_string() reversed when using in switch case statements...
Can someone double check me here, but I think I found a bug... ?php /* $ php -v PHP 5.3.6 with Suhosin-Patch (cli) (built: Apr 28 2011 14:20:48) Copyright (c) 1997-2011 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans */ function test($v) { var_dump($v); if (is_string($v)) echo FOUND A STRING.\n; if (is_null($v)) echo FOUND A NULL.\n; switch ($v) { case is_string($v): echo I think v is a string, so this is broken.\n; break; case is_null($v): echo I think v is null, so this is broken.\n; break; case is_object($v): $v = '{CLASS::'.get_class($v).'}'; echo I think v is a class $v\n; break; case is_bool($v): $v = ($v) ? '{TRUE}' : '{FALSE}'; echo I think v is boolean $v\n; break; case is_array($v): $v = '['.implode(',',$v).']'; echo I think v is an array $v\n; break; case is_numeric($v): echo I think v is a number $v\n; break; } } class SomeClass {} test(''); test(null); test(new SomeClass()); test(true); test(69); test(array(1,2,3,4,5)); /* Output will be: string '' (length=0) FOUND A STRING. I think v is null, so this is broken. null FOUND A NULL. I think v is a string, so this is broken. object(SomeClass)[1] I think v is a class {CLASS::SomeClass} boolean true I think v is boolean {TRUE} int 69 I think v is a number 69 array 0 = int 1 1 = int 2 2 = int 3 3 = int 4 4 = int 5 I think v is an array [1,2,3,4,5] */ ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] is_null() and is_string() reversed when using in switch case statements... [SOLVED]
-Original Message- From: Simon J Welsh [mailto:si...@welsh.co.nz] Sent: Thursday, July 14, 2011 7:29 PM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] is_null() and is_string() reversed when using in switch case statements... On 15/07/2011, at 1:58 PM, Daevid Vincent wrote: function test($v) { var_dump($v); if (is_string($v)) echo FOUND A STRING.\n; if (is_null($v)) echo FOUND A NULL.\n; switch ($v) { case is_string($v): echo I think v is a string, so this is broken.\n; break; case is_null($v): echo I think v is null, so this is broken.\n; break; case is_object($v): $v = '{CLASS::'.get_class($v).'}'; echo I think v is a class $v\n; break; case is_bool($v): $v = ($v) ? '{TRUE}' : '{FALSE}'; echo I think v is boolean $v\n; break; case is_array($v): $v = '['.implode(',',$v).']'; echo I think v is an array $v\n; break; case is_numeric($v): echo I think v is a number $v\n; break; } } In both cases, $v is equivalent to false, so is_string(NULL) = false == NULL == $v, likewise for is_null($v); You're most likely after switch(true) { . } rather than switch($v) --- Simon Welsh Admin of http://simon.geek.nz/ Ah! Thanks Simon! That is exactly right. Doh! I should have thought of that... *smacks head* Here is the fruit of my labor (and your fix)... /** * Useful for debugging functions to see parameter names, etc. * Based upon http://www.php.net/manual/en/function.func-get-args.php#103296 * * function anyfunc($arg1, $arg2, $arg3) * { * debug_func(__FUNCTION__, '$arg1, $arg2, $arg3', func_get_args()); * //do useful non-debugging stuff * } * * @access public * @return string * @param string $function_name __FUNCTION__ of the root function as passed into this function * @param string $arg_names the ',,,' encapsulated parameter list of the root function * @param array $arg_vals the result of func_get_args() from the root function passed into this function * @param boolean $show_empty_params (FALSE) * @author Daevid Vincent * @date 2011-17-14 * @see func_get_args(), func_get_arg(), func_num_args() */ function debug_func($function_name, $arg_names, $arg_vals, $show_empty_params=FALSE) { $params = array(); echo $function_name.'('; $arg_names_array = explode(',', $arg_names); //var_dump($arg_names, $arg_names_array, $arg_vals ); foreach($arg_names_array as $k = $parameter_name) { $v = $arg_vals[$k]; //echo k = $parameter_name = $k and v = arg_vals[k] = $vbr\n; switch(true) { case is_string($v): if ($show_empty_params) $v = '.$v.' ; break; case is_null($v): if ($show_empty_params) $v = '{NULL}'; break; case is_bool($v): $v = ($v) ? '{TRUE}' : '{FALSE}'; break; case is_array($v): (count($v) 10) ? $v = '['.implode(',',$v).']' : $v = '[ARRAY]'; break; case is_object($v): $v = '{CLASS::'.get_class($v).'}'; break; case is_numeric($v): break; } if ($show_empty_params || $v) $params[$k] = trim($parameter_name).': '.$v; } echo implode(', ',$params).)br/\n; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Your language sucks because...
(at the risk of starting another $h!t storm like the last time) http://wiki.theory.org/YourLanguageSucks#PHP_sucks_because: ;-)
[PHP] Mangling URLs for RewriteRule parsing
I'm fumbling trying to think of a nice easy way to mangle my URLs within PHP for SEO and apache's RewriteRules magic. Given a basic rule like this: RewriteCond ^/foo/movie/genre/([-a-z\|]*)_([-a-z\|]*)/([0-9]+)/videos.html$ RewriteRule /browse_scenes.php?genre_id=${genres:$2}pg=$1%{QUERY_STRING} [NC,L] I currently have a wrapper createPageLink() that right now just spits back the 'ugly' URL style. (ie. the 'Rule' portion), but what I want it to do is spit back the nice 'Cond' part instead) Do I just have to make a giant switch/case statement for all the 'browse_scenes.php' and other .php pages? It seems to me that I should be able to dynamically build the URLs that are inserted into my .php page (the ones that show up in the browser bottom bar on hover). I'm fairly flexible at this point as I'm just starting to do this SEO stuff, so I thought I'd ask if someone has a nice function or class or something that has already solved this kind of problem? Or is it such that every site is unique and no such 'generic' kind of wrapper exists? I guess I'm thinking of methodology or best practice type code, rather than a turnkey solution if none exists. d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Doctrine madness!
-Original Message- From: Nathan Nobbe [mailto:quickshif...@gmail.com] Sent: Thursday, June 16, 2011 9:51 AM To: php-general@lists.php.net Subject: [PHP] Doctrine madness! Hi gang, If anyone out there has some experience w/ Doctrine now would be a great time to share it! Yeah, I've used Doctrine as part of Symfony. Both suck balls and are a perfect example of why you should NEVER use frameworks. Lesson learned the hard way. Re-write with your own MySQL wrappers and for the love of God and all that is holy do NOT make it an ORM wrapper. KTHXBYE. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Doctrine madness!
-Original Message- From: Eric Butera [mailto:eric.but...@gmail.com] Sent: Thursday, June 16, 2011 2:58 PM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] Doctrine madness! On Thu, Jun 16, 2011 at 5:37 PM, Daevid Vincent dae...@daevid.com wrote: -Original Message- From: Nathan Nobbe [mailto:quickshif...@gmail.com] Sent: Thursday, June 16, 2011 9:51 AM To: php-general@lists.php.net Subject: [PHP] Doctrine madness! Hi gang, If anyone out there has some experience w/ Doctrine now would be a great time to share it! Yeah, I've used Doctrine as part of Symfony. Both suck balls and are a perfect example of why you should NEVER use frameworks. Lesson learned the hard way. Re-write with your own MySQL wrappers and for the love of God and all that is holy do NOT make it an ORM wrapper. KTHXBYE. I do believe that was the most eloquent and enlightened email that has ever graced my inbox. Thank you for taking the time to edify us with that pithy reply. Glad I could be of service. There was no point in elaborating more on either Doctrine or Symfony any further. Sometimes, like that guy that fell down the canyon, you have to cut your own arm off with a swiss army knife to save your life. In this case, get rid of Doctrine or any other ORM, despite the painful operation, and save your project from a slow and agonizing death. ORM's and ActiveRecord style wrappers, while sounding sexy -- like the babe on the other end of a 1-900 number -- usually turn out to be fat and bloated. All that magic comes at a price. This is why Ruby on Rails has started to fall out of favor with ANY big shop and you are hearing less and less about it. It's cute and seems magnificent at first, but quickly starts to show its limitations and short-comings when you REALLY try to use it. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Doctrine madness!
-Original Message- From: Nathan Nobbe [mailto:quickshif...@gmail.com] Sent: Thursday, June 16, 2011 5:39 PM To: Daevid Vincent Cc: php-general@lists.php.net Subject: RE: [PHP] Doctrine madness! On Jun 16, 2011 5:31 PM, Daevid Vincent dae...@daevid.com wrote: -Original Message- From: Eric Butera [mailto:eric.but...@gmail.com] Sent: Thursday, June 16, 2011 2:58 PM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] Doctrine madness! On Thu, Jun 16, 2011 at 5:37 PM, Daevid Vincent dae...@daevid.com wrote: -Original Message- From: Nathan Nobbe [mailto:quickshif...@gmail.com] Sent: Thursday, June 16, 2011 9:51 AM To: php-general@lists.php.net Subject: [PHP] Doctrine madness! Hi gang, If anyone out there has some experience w/ Doctrine now would be a great time to share it! Yeah, I've used Doctrine as part of Symfony. Both suck balls and are a perfect example of why you should NEVER use frameworks. Lesson learned the hard way. Re-write with your own MySQL wrappers and for the love of God and all that is holy do NOT make it an ORM wrapper. KTHXBYE. I do believe that was the most eloquent and enlightened email that has ever graced my inbox. Thank you for taking the time to edify us with that pithy reply. Glad I could be of service. There was no point in elaborating more on either Doctrine or Symfony any further. You've been even less helpful than the broken community surrounding doctrine. Thanks for your effort daevid, I know you tried hard ;) -nathan You asked if anyone had experience with Doctrine and to share the experience. I did just that *wink*. I never claimed to have a solution to your Doctrine problem, other than the fact that Doctrine is in itself the problem. You are in a recursive loop. :) Think of me as the return;. You're welcome. In all my 25+ years of coding experience with any language and especially PHP, I've learned the hard way that the one-size-fits-all approach of a generic framework and the bloat of an ORM just doesn't work. It looks wonderful, trust me, I've fallen prey to its sultry gaze myself. Hell, I've even written tools that started to look like ORMs and Frameworks, and then there comes a point when you realize their cost is too high. You're better off (IMHO) making some very efficient wrapper functions for sql_query(), sql_save() [does insert/update intelligently], sql_delete(), etc. and not get all fancy with making a SQL class/object and all that crap either. OOP is great for many things, but it's not the answer to everything and developers need to know when to use the right tool for the job. It has also been my experience that a SQL wrapper is best as a procedural system since it's called so frequently and often. Doing some silly: $con = new DBConnection(); $con-query('select * from foo'); $myresults = $con-getResults(); $con-close(); Or whatever is a waste. $myresults = sql_query('select * from foo'); Is far more efficient and easier to read. Let the function open a connection, and do all the work. The ORM dealios complicate things, as now you have some stupid YAML file to maintain, and you have to make objects that relate to other objects (1:M, M:M, etc.) and after a while, you start to think, shit, I could have done this with like 3 SQL statements. The ORM's fatal flaw is it's one-size-fits-all Achilles heel. Example: We used to have this crontab job that would update news stories from RSS feeds we harvested around the web. It was taking HOURS to complete. Mostly because for each story, we had to create a new Doctrine object thingy and all the related table objects and then update the instance object, then -save() or whatever. Do that over a hundred-thousand objects and stuff starts to slow down. We converted it to use straight SQL calls and it ran in under 10 minutes. YES. From HOURS to minutes. An order of magnitude faster. Just trying to save you (and anyone else) the time and trouble. I don’t dislike ORM and frameworks because I have some axe to grind, like I used to write a framework and it cheated on me and so I'm all jaded... No. I dislike them from experience over years of practical real-world implementations. I have tried them. I *WANT* to like them, I really do. I was very excited when Zend Framework came out... and then... I used it, and realized it was like the others. Bloat. Slow. Confusing. Cumbersome. The last thing I'll leave you with is that, when you start to rely upon one of these ORM/PHP frameworks, you're not only stuck with it -- warts and all -- but you have to TRAIN other people to use it as well! If you find a bug, you either have to maintain it forever in your own branch, or hope the developers of the framework fix it. When you hire new people, you always have to add some caveat to the job request, Zend Framework, Doctrine
RE: [PHP] Doctrine madness!
-Original Message- From: Eric Butera [mailto:eric.but...@gmail.com] Sent: Thursday, June 16, 2011 5:53 PM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] Doctrine madness! On Thu, Jun 16, 2011 at 7:32 PM, Daevid Vincent dae...@daevid.com wrote: -Original Message- From: Eric Butera [mailto:eric.but...@gmail.com] Sent: Thursday, June 16, 2011 2:58 PM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] Doctrine madness! On Thu, Jun 16, 2011 at 5:37 PM, Daevid Vincent dae...@daevid.com wrote: -Original Message- From: Nathan Nobbe [mailto:quickshif...@gmail.com] Sent: Thursday, June 16, 2011 9:51 AM To: php-general@lists.php.net Subject: [PHP] Doctrine madness! Hi gang, If anyone out there has some experience w/ Doctrine now would be a great time to share it! Yeah, I've used Doctrine as part of Symfony. Both suck balls and are a perfect example of why you should NEVER use frameworks. Lesson learned the hard way. Re-write with your own MySQL wrappers and for the love of God and all that is holy do NOT make it an ORM wrapper. KTHXBYE. I do believe that was the most eloquent and enlightened email that has ever graced my inbox. Thank you for taking the time to edify us with that pithy reply. Glad I could be of service. There was no point in elaborating more on either Doctrine or Symfony any further. Sometimes, like that guy that fell down the canyon, you have to cut your own arm off with a swiss army knife to save your life. In this case, get rid of Doctrine or any other ORM, despite the painful operation, and save your project from a slow and agonizing death. ORM's and ActiveRecord style wrappers, while sounding sexy -- like the babe on the other end of a 1-900 number -- usually turn out to be fat and bloated. All that magic comes at a price. This is why Ruby on Rails has started to fall out of favor with ANY big shop and you are hearing less and less about it. It's cute and seems magnificent at first, but quickly starts to show its limitations and short-comings when you REALLY try to use it. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I'm sorry but this is absolute rubbish. I used to write my queries by hand, but over time you start to realize that perhaps, maybe writing out thousands of identical lines of code over hundreds of projects might not be an efficient usage of time. I never said to do that. I said to write your own wrappers and your own framework for YOUR needs. A one-size-fits all solution is never going to be as clean or efficient as your own code. See previous rant and I'm sure there are archives of my other rants on the failure that is ORM Frameworks. What is the more common question from clients: why is this so slow, or, client asks why is this not finished yet? ...until the project gains traction and starts to get users and then it will be, why is this so slow?! I do like the half-hearted diatribe against ROR, which I will assume is a wildcard, allow any language/framework combination to stand-in. Yes, frameworks as a whole suck. However, I will concede the one framework I do enjoy and find much more useful is jQuery, if for no other reason than it handles all the minutia and BS of browser incompatibilities and parsing the DOM in JS. It's fairly lightweight and works very well for the most part. Even having said that, I really only use jQuery on a need-to-use basis and not for everything JS related. But once you have to include it in a page for some necessary reason, you might as well continue to use it in the page since you've already downloaded it to the client and it makes the code easier to read vs. jumping in and out of raw JS and jQueryScript(tm) The real take-away message here is that you're trying to paint everything with the brush that you see the world in, while the reality is that not everyone has your requirements. Personally, I don't enjoy If it's a project bigger than your own personal website, then eventually you WILL have my requirements. trying to mess around with ill-conceived, backwards-compatible adhering designs from 12 years ago. I understand that growth is organic and deal with it on a daily basis in my own projects. Hence, I use a framework and other tooling that allows me to complete jobs in a tidy and orderly fashion. Name me some LARGE popular sites that use frameworks? Again, if you want to make your little companies website or personal page, go for it. Frameworks are great for prototypes and simple stuff. Anything more and you're going to hate life after a year or two using it. Fact. If I need something a little more cutting-edge I can always drop down lower on the stack to bypass PHP with other techniques like caching or bypassing the framework altogether
RE: [PHP] Doctrine madness! huh?
out XSS out of the box. Of course, with diligence and time we can all overcome these things, but that does not mean someone with the ambition to bang together a quick website for a relative understands the real perils they're getting into - I certainly did not. I'm sure Anonymous or any other hacker worth worrying about isn't looking to deface your grandmother's website. ;-) Yes, ;-) indeed. When you resort to personal attacks on supposed wealth and my poor grandmother the argument is over. In case you don't understand, you lost for name calling with no sustenance in your Huh? Name calling? What are you talking about. You made a reference to bang together a quick website for a relative and how the frameworks give you more security and some other stuff. My jest, which clearly you took way too personally or something, was only trying to say that for a 'personal website', your fears of attack by hackers (Anonymous being the biggest out there), is pretty slim to none. And even if you did get hacked (most likely by some automated script kiddie bot), who cares -- including you -- because it's just a silly personal home-page with pictures of relatives and other stupid stuff nobody but a very very very small circle of people give a crap about, and therefore not worth a true hacker's time. I didn't imply wealth or lack thereof, nor did I call anyone names. Apologies for the misunderstanding. Jeesh. d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] CodeBubbles for Eclipse Beta available!
While not PHP specifically, this is a plugin for Eclipse that is an entirely new paradigm in coding IDE and I've been watching waiting for it for over a year now. I post it here because [a] it's pretty much the coolest thing since the invention of the IDE itself. [b] it's real and actually not vaporware [c] it's NOW open sourced!! [d] I'm hoping someone will take the reins and start a PHP version Code Bubbles Beta generally available for Java on top of Eclipse!! http://www.cs.brown.edu/people/spr/codebubbles/ More info here: http://www.andrewbragdon.com/codebubbles_site.asp http://lambda-the-ultimate.org/node/3854 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] phpsadness - the second tangent...
Really? This thread is going to tangent yet again to something completely irrelevant? FWIW, I used some stupid WinLIKE JS framework by http://ceiton.com These bastards haven't updated it since 2007 http://wiki.winlike.net/index.php/Version_History Normally not a big deal, but they patented it (or tried), and it's all minified and IN GERMAN! So trying to figure out how and where to remove that browser check has been a futile effort that I just don't care to spend any more time on. This is yet another reason and example as to why I HATE frameworks. I should have never used their crappy one and just built everything myself. My current PERSONAL site is starting to show its age and is due for a re-vamp, but honestly I just have too much other work on my plate that pays me. 90% of the people out there use FF or IE and so I don't really care about Safari or Opera or the other fringe browsers for my PERSONAL site. -Original Message- From: Tamara Temple [mailto:tamouse.li...@gmail.com] Sent: Saturday, June 04, 2011 10:09 PM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] phpsadness - P.C. shmee seee. On Jun 3, 2011, at 3:52 PM, Daevid Vincent wrote: ...actually, I do have some good ones here: http://daevid.com/content/examples/procmail.php It appears your browser does not support some of the advanced features this site requires. Please use Internet Explorer or Firefox. ROFL. Good one. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] phpsadness - P.C. shmee seee.
Reminds me (obliquely) of an entry in the index for The C Programming Language for recursion, which points right back to that index page. I about doubled over when I first discovered it. That's hilarious. I love subtle humor like that. This whole thread seems to echo the original subject recursively too... ;-) How sad this topic has devolved from what was IMHO a fairly honest page someone created (with valid grievances) to one of religion and name calling. I tried to avoid commenting at all but I do have to agree with Tedd here: Instead, I think you saw an opportunity to be politically correct and rise to the occasion in righteous indignation. I personally think Politically Correctness is a load of $h!t and causes more harm and trouble than it's worth. I'm so sick of it being dictated to me everywhere from media to schools to work to now even a programming language list. People need thicker skins. If you are so easily offended, then block that person's email from your mailbox. It's called the 1st Amendment. I may not agree with, or even like the things you say, but I'll defend to the death your right to say it -- whatever it is! I don't agree with radical Muslims wanting to kill me either, but I'll defend their right to protest and say whatever they want (as long as it's true!). Same goes for KKK or any other extremist group. http://en.wikipedia.org/wiki/First_Amendment_to_the_United_States_Constitution Ross Perot said it best, every time you pass a new law, you give up some of your freedoms. And this P.C. crap is just an un-official law that is being imposed on people. People aren't visually impaired, they are blind. They're not dwarfs or little people, they're midgets. A retard is handicapped and isn't mentally challenged. (there, how many people did I just offend?) DEAL WITH IT. I have a big nose and I'm balding from Alopecia -- I'm not olfactory gifted or follicly deficient either. Didn't your mommas ever teach you, sticks and stones will break my bones, but names can never hurt me?? And don’t even get me started on stereotypes -- because those are based on true observations too! If you don't like your stereotype, then collectively as a people, you need to change it. we didn’t make up your stereotype, you did! We just noticed it and pointed it out to you -- you're welcome. ...and watch this: http://www.youtube.com/watch?v=iqVhtHapFW4 http://www.youtube.com/watch?v=UnDIvZKs4dA http://www.metacafe.com/watch/457799/allahu_akbar/ http://nation.foxnews.com/germany-airport-shooting/2011/03/03/obama-administration-refuses-call-attack-germany-act-terrorism shoot, I wouldn't be surprised if I just got myself on some government watch list now that I googled for those videos! ...let the ~/.procmailrc filters begin! Here use this: :0 * ^FROM.*daevid | (echo From: POSTMASTER@YOUR_NAME_HERE.com; \ echo To: $FROM; \ echo Subject: You have lost your email privileges to me you politically incorrect P.O.S.; \ echo ;\ echo I have banned you from emailing me and I hope you die painfully.\n \ ) | $SENDMAIL -oi -t /dev/null ...actually, I do have some good ones here: http://daevid.com/content/examples/procmail.php :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] phpsadness
Damn. Ironically, I wanted to write something short and succinct like that ... then I got all worked up and started to rant. Well said 'guy with my same name'. :) -Original Message- From: David Harkness [mailto:davi...@highgearmedia.com] Sent: Friday, June 03, 2011 1:47 PM To: PHP General Subject: Re: [PHP] phpsadness The original PHP Sadness page didn't actually make me sad. This thread, however, *is*. Can we all agree that we have different opinions on what makes an appropriate joke and move on? Here's to less sadness in the world . . . David -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] phpsadness
A friend sent me this URL today. While amusing, he's got many valid points and I certainly share in his frustration. http://www.phpsadness.com
RE: [PHP] Posts that include bracket OT bracket
-Original Message- From: paras...@gmail.com [mailto:paras...@gmail.com] On Behalf Of Daniel Brown Sent: Monday, May 23, 2011 11:20 AM To: tedd Cc: php-general@lists.php.net Subject: Re: [PHP] Posts that include bracket OT bracket On Mon, May 23, 2011 at 11:33, tedd tedd.sperl...@gmail.com wrote: Hi gang: When did the list start rejecting subject lines that contain [OT]? At least several years ago. It bounces back to say that off-topic mail isn't accepted, blah, blah, blah. It's kind of silly if you ask me as it doesn't prevent anything since any mildly intelligent person will just omit the [OT] and re-submit (case in point), and it prevents other users from doing any kind of email filtering on [OT]. It's basically punishing the sender for trying to do the right thing. *sigh* -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] observer pattern
-Original Message- From: Eric Butera [mailto:eric.but...@gmail.com] Sent: Friday, May 20, 2011 2:25 PM To: PHP Subject: Re: [PHP] observer pattern [whoops didn't hit reply-all] On Wed, May 18, 2011 at 5:18 AM, Ken Guest k...@linux.ie wrote: Lo, so, I'm wondering - how many of you use the observer pattern in php; and if so, do you implement it 'standalone' or with the spl classes? Is there any particular advantage to doing it your way; whichever your way is? Ken -- http://blogs.linux.ie/kenguest/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I use it quite a bit over the various projects I maintain. It allows subjects to trigger events that observers can process if they're interested, or better yet, completely ignore. This allows standardized code bases to create nice hooks that allow extensibility without needing to place one-off code inside the main project. A quick example might be on saving a record in your code, it triggers an event, then an observer in a custom site watches for said event and injects/updates a search entry in Lucene. This way one site can have a custom search engine that another site might not need. I started off with the concepts I found in http://examples.stubbles.net/docroot/events/ but created my own because I wanted something stand-alone. Well, you (or in this case, *I*) learn something new every day. I had no idea PHP could do observers. How very Java (and neat!) Granted, it is just a design pattern, but to have the SplObserver stuff built in is pretty cool. What version of PHP is this available from? The web page doesn't say. http://www.labelmedia.co.uk/blog/posts/php-design-patterns-observer-pattern.html http://cormacscode.wordpress.com/2010/10/12/practical-example-php-implementation-of-the-observer-pattern/ http://www.php.net/manual/en/book.spl.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Short tag: why is it bad practice?
-Original Message- From: Joshua Kehn [mailto:josh.k...@gmail.com] Sent: Tuesday, May 10, 2011 8:19 AM To: Andre Polykanine Cc: php-general@lists.php.net Subject: Re: [PHP] Short tag: why is it bad practice? On May 10, 2011, at 11:11 AM, Andre Polykanine wrote: Hi everyone, Many times I heard that the following two peaces of code are written in a bad manner: 1. ? echo Hello, world!; ? 2. form action=script.php method=post pYour e-mail: input type=text id=uemail name=uemail value=?=$f['Email']?/p ... /form As for now, I use both quite often. Why is this considered not kosher, I mean, good coding practice? Thanks! -- With best regards from Ukraine, Andre Skype: Francophile Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com/menelion Because short tags aren't always enabled and can cause things to break when deploying code to different environments. Best practice dictates that your code should be as environmentally independent as possible. It's another few characters, why neglect it? This is always a source of confusion. http://www.bin-co.com/php/articles/using_php_short_tags.php ?= $foo ? is generally NOT what the short tags controversy are about. It's the use of ? Some php here ? vs. ?php some php here ? While it is true that the 'short_open_tag' directive enables both (for some stupid reason), the issue is that it's poor form to use JUST ? And not ?php just as it's a bad idea to use % % (asp tags). Using ?= is perfectly fine and in my personal and professional opinion, preferred to the uglier ?php echo $foo; ? way This topic was very heated when the core PHP developers were going to remove the ? Form all together in future PHP 6 versions and everyone got their panties in a bunch because they assumed it meant the ?= form too (which it did not). http://php.net/manual/en/ini.core.php http://www.php.net/~derick/meeting-notes.html#remove-support-for-and-script- language-php-and-add-php-var -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Dotnet Remoting
-Original Message- From: Bastien [mailto:phps...@gmail.com] Sent: Thursday, February 24, 2011 4:18 AM To: Gary Cc: php-general@lists.php.net Subject: Re: [PHP] Dotnet Remoting On 2011-02-24, at 5:17 AM, Gary php-gene...@garydjones.name wrote: This is purely of academic interest to me, nothing urgent. I'm just wondering if it's possible to do remoting with PHP's DOTNET class (http://php.net/manual/en/class.dotnet.php) which I didn't even know existed until yesterday. If it is, is there any reason that DOTNET is a Windows only extension? Like I say, it's just something I'm curious about. -- GaryPlease do NOT send me 'courtesy' replies off-list. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php How about because dotnet and the dotnet framework is a windows product? Are you sure about that Bastien? ;-) http://www.mono-project.com This is pretty robust and used by many companies, including Fogbugz (I know, we use it here at Panasonic). While .NET started as a Microsoft way to unify their VB and J++ (now C#), it has gone past that. It is a language framework like any other language framework. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] root of PHP found!
Aha! I am working for the company that was the root of PHP! http://www.panasonic.net/history/founder/chapter3/story3-02.html ;-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] A bad design decision or pure genius?
-Original Message- From: li...@pruimphotography.com [mailto:li...@pruimphotography.com] Sent: Thursday, January 13, 2011 4:50 PM To: php-general@lists.php.net Subject: [PHP] A bad design decision or pure genius? Hey Everyone, I have a question about php javascript... Yes I know this forum is for php BUT I needed an opinion on where to look for stuff... I have a application that I'm working on that uses google maps to display interactive maps (using javascript) on the website. I now have the need to display multiple maps on the same page and from what I can tell I have to create new instances and variables for all of them... What I'm wondering is since I know very little javascript would it be bad to create a PHP function to write the java code for the proper number of maps I need to display? The map info is being pulled from a database where events are being added and could contain 2 or 200 maps... Or should I learn javascript and figure out how to create a loop in there so that I can just loop it in the java and not repeat code? Thanks for any assistance you can give! Jason Pruim pru...@gmail.com Not sure why you would need to show more than a single map at any given time. Therefore why not use PHP to show a list of possible maps and when the user clicks on one, use AJAX to populate a single map on demand? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] [security] PHP has DoS vuln with large decimal points
The error in the way floating-point and double-precision numbers are handled sends 32-bit systems running Linux, Windows, and FreeBSD into an infinite loop that consumes 100 percent of their CPU's resources. Developers are still investigating, but they say the bug appears to affect versions 5.2 and 5.3 of PHP. They say it could be trivially exploited on many websites to cause them to crash by adding long numbers to certain URLs. ?php $d = 2.2250738585072011e-308; ? The crash is also triggered when the number is expressed without scientific notation, with 324 decimal places. Read on... http://www.theregister.co.uk/2011/01/04/weird_php_dos_vuln/ -- Daevid Vincent http://daevid.com There are only 11 types of people in this world. Those that think binary jokes are funny, those that don't, and those that don't know binary. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Even Newer-Viewing Problem
I have Linux with Firefox reading mail at yahoo. All the messages I get in the digest contain html elements making it very hard to read the messages. Is there anything I can do to make the messages come in clear text? or get this system to read the html in the digest? Thank you, Fr. Vincent Benoit, OP
RE: [PHP] Use PHP the way God intended...
-Original Message- From: Robert Cummings [mailto:rob...@interjinn.com] Sent: Friday, December 10, 2010 6:54 AM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] ORM doctrine On 10-12-09 10:41 PM, Daevid Vincent wrote: Use PHP the way God intended it to be used. Could you cite a reference for where God states his intentions on PHP? Thanks, Rob. I believe it was in the Old PHPestament, The Book of Rasmus chapter 42 verse 69... 66 ... 67 And behold as he opened the 5th point 2nd seal 68 and the Lord said unto him, 69 Thou shalt not use frameworks, 70 for they art cumbersome 71 and a bastardization of mine own language 72 ... It goes on to talk about using ?= instead of ?php echo And how you should always put the closing ? on the page bottom, But I digress... ROFL! :D -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] empty() in email message
- Original message - From: Gary gp...@paulgdesigns.com To: php-general@lists.php.net php-general@lists.php.net Date: Monday, December 13, 2010, 7:47:49 PM Subject: [PHP] empty() in email message I have an email message $msg = 'Name: $fname ' . ' $lname\n' . Phone: $phone\n . Email: $email\n and it works fine, however in this message there are about 30 variables that are being called...as such . Order: beefschnitzel $beefschnitzel\n . Order: beefstrips $beefstrips\n . Order: cheesesausage $cheesesausage\n . Order: crumbedsausage $crumbedsausage\n . Order: chucksteak $chucksteak\n . Order: cornedbeef $cornedbeef\n . Order: dicedsteak $dicedsteak\n . Order: filletmignon $filletmignon\n I want to only send the message if the submitter enters an amount in the form for the corresponding variable, instead of having a bunch of empty messages. So I have been trying to use the empty() function as such: . if empty($beefolives){''} elseif (isset($beefolives)) { 'Order: beefolives $beefolives\n'} You are setting this up fundamentally wrong. You should be using an array and looping through it. Something like: $myorder['cowface'] = 1; $myorder['beefenweiner'] = 2; $myorder['chucksteak'] = 1; foreach ($myorder as $item = $quantity) { echo Order: $item x $quantity\n; } Then your array only contains the items someone actually puchased and how many. d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ORM doctrine
-Original Message- If you value CPU time over developer time, by all means avoid ORM frameworks (and *all* frameworks). The point of a common framework is to trade a small bit of performance for a large amount of developer time. If you will only use the framework once, the payoff will be much less. The goal is to choose frameworks that you can leverage again and again. I disagree. If you use a framework, then you're stuck with it. Bugs and all (and trust me there are bugs and limitations you WILL run into). If it's your code, you can fix it. If it's someone elses' you have to submit a bug report and HOPE they fix it. If they don't you are now forced with either patching every new release or working around it. As for training, you will be able to hire another developer that knows Doctrine. Doubtful. It's hard enough to find skilled PHP developers as it is. Everyone and their mother THINKS they're a LAMP guy. Test them. You quikly find out that buzzwords on a paper resume are not the same as a real developer. It will be impossible to find a developer *anywhere* that understands your home-grown framework without training. That's just it. DO NOT make a framework. Make some helper routines for common tasks like sql_query(), sql_insert(), sql_update(), sql_select_box(), etc. and stick to the basics. Frameworks are a waste of time and energy -- homegrown or off-the-shelf. They try to be all things to all people and turn into a jack of trades, master of none. They're bloated and cumbersome and force you to wedge square pegs into round holes all the time. Nor will you get help with bugs in your framework or be able to discuss better ways to use it on forums. That's what your employees, team-mates, customers, testers, etc. are for... If you're making JoeBlowsRinkyDink.com then go for the framework if you want to play with it for the massochistic experience and to learn your lesson the hard way. But don't use it for paying customers and certainly don't use it in an enterprise level -- it will be the death nail to your project ultimately. Use PHP the way God intended it to be used. I leave you with this old Poll I posted: http://www.rapidpoll.net/show.aspx?id=8opnt1e -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ORM doctrine
Avoid these ORM things like the plague! They seem great in theory, but if you're doing anything serious, they will quickly get in your way. Not to mention all that fancy ORM doesn't come without a price. It costs in terms of speed, as well as training. You're much better off to make your custom tools for your particular application. -Original Message- From: Alexandru Patranescu [mailto:dreal...@gmail.com] Sent: Wednesday, December 08, 2010 9:10 PM To: Tommy Pham Cc: PHP Subject: Re: [PHP] ORM doctrine Doctrine is mature and well I've seen it plenty of times companies using it. Of course it handles multi table joins but I think it's main purpose is not related to users writing joins... It's an ORM, you just read and write objects. Caching is something that must be there and you can read more on wiki: http://en.wikipedia.org/wiki/Doctrine_%28PHP%29 Alex On Thu, Dec 9, 2010 at 5:02 AM, Tommy Pham tommy...@gmail.com wrote: Hi, Has anyone used doctrine before? I know Nathan mentioned it in the other thread but I was wondering how does it handle multi table joins query, about its performance and whether it uses any type of caching. Thanks, Tommy -- 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] How can I call GD's imagepng() directly from my class?
I have a class that does some massive computations to compute a LOPA (layout of passenger aircraft). I currently render it in an HTML table with little seats. I want to now make this using GD so I can show entire fleets of aircraft on one page. Inside my LOPA.class.php I have this method: public function render_image() { $my_img = imagecreate( 200, 80 ); $background = imagecolorallocate( $my_img, 0, 0, 255 ); $text_colour = imagecolorallocate( $my_img, 255, 255, 0 ); $line_colour = imagecolorallocate( $my_img, 128, 255, 0 ); imagestring( $my_img, 4, 30, 25, Test Image, $text_colour ); imagesetthickness ( $my_img, 5 ); imageline( $my_img, 30, 45, 165, 45, $line_colour ); header( Content-type: image/png ); header('Content-Length: ' . strlen($my_img)); imagepng( $my_img ); imagecolordeallocate( $line_color ); imagecolordeallocate( $text_color ); imagecolordeallocate( $background ); imagedestroy( $my_img ); } And I'm trying to call it from a PHP page like so: img src=?php $my_lopa-render_image(); ? alt=Image created by a PHP script width=200 height=80 But it doesn't show the picture. :\ If I take the contents of that function and dump it into a gdtest.php file and call it like this however, it does work: img src=images/gdtest.php alt=Image created by a PHP script width=200 height=80 So what am I doing wrong above that I can't just call it from my class? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How can I call GD's imagepng() directly from my class?
-Original Message- From: Daevid Vincent [mailto:dae...@daevid.com] Sent: Monday, December 06, 2010 4:02 PM To: php-general@lists.php.net Subject: [PHP] How can I call GD's imagepng() directly from my class? I have a class that does some massive computations to compute a LOPA (layout of passenger aircraft). I currently render it in an HTML table with little seats. I want to now make this using GD so I can show entire fleets of aircraft on one page. Inside my LOPA.class.php I have this method: public function render_image() { $my_img = imagecreate( 200, 80 ); $background = imagecolorallocate( $my_img, 0, 0, 255 ); $text_colour = imagecolorallocate( $my_img, 255, 255, 0 ); $line_colour = imagecolorallocate( $my_img, 128, 255, 0 ); imagestring( $my_img, 4, 30, 25, Test Image, $text_colour ); imagesetthickness ( $my_img, 5 ); imageline( $my_img, 30, 45, 165, 45, $line_colour ); header( Content-type: image/png ); header('Content-Length: ' . strlen($my_img)); imagepng( $my_img ); imagecolordeallocate( $line_color ); imagecolordeallocate( $text_color ); imagecolordeallocate( $background ); imagedestroy( $my_img ); } And I'm trying to call it from a PHP page like so: img src=?php $my_lopa-render_image(); ? alt=Image created by a PHP script width=200 height=80 But it doesn't show the picture. :\ If I take the contents of that function and dump it into a gdtest.php file and call it like this however, it does work: img src=images/gdtest.php alt=Image created by a PHP script width=200 height=80 So what am I doing wrong above that I can't just call it from my class? I got a little 'hack' further, but not loving it. Maybe I'll move the image to a $_SESSION variable and then have the gdtest.php pull it and echo it that way public function render_image() { $my_img = imagecreate( 200, 80 ); $background = imagecolorallocate( $my_img, 0, 0, 255 ); $text_colour = imagecolorallocate( $my_img, 255, 255, 0 ); $line_colour = imagecolorallocate( $my_img, 128, 255, 0 ); imagestring( $my_img, 4, 30, 25, Test Image, $text_colour ); imagesetthickness ( $my_img, 5 ); imageline( $my_img, 30, 45, 165, 45, $line_colour ); ob_start(); header( Content-type: image/png ); header('Content-Length: ' . strlen($my_img)); imagepng( $my_img ); $final_image_data = ob_get_contents(); ob_end_clean(); imagecolordeallocate( $line_color ); imagecolordeallocate( $text_color ); imagecolordeallocate( $background ); imagedestroy( $my_img ); echo 'data:image/png;base64,'.base64_encode($final_image_data); } img src=?php $my_lopa-render_image(); ? width=200 height=80 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP]any way to iterate the fields in a class
-Original Message- From: ?? [mailto:xiaohan2...@gmail.com] Sent: Thursday, November 25, 2010 12:21 AM To: php-general@lists.php.net Subject: [PHP]any way to iterate the fields in a class Actually, what I am seeking is how to assign values to the fields in a class via an array. I have tried like this. However failed. I have a class. *class book{ var name;* *var price;* *}* * * And I have got an array. *$array=array('name'='harry potter','price'='$122');* By using function *extract(), *I assign the values to $name and $price while not $this-name and $this-price, which is not what I want. So I am thinking iterating the fields in an array and assign the values each by each through an array. Is there any way to assign values to the fields in a class via an array. Thanks in advance! /** * generate a key/value pair from the class' variables. * * @access public * @return array * @author Daevid Vincent [daevid.vinc...@panasonic.aero] * @version 1.0 * @date 01/27/09 */ public function get_array() { $row = array(); foreach($this as $key = $value) $row[$key] = $value; return $row; } /** * Shows all exposed variables in this class * * @access public * @return array * @paramboolean $print to print out each value * @author Daevid Vincent [daevid.vinc...@panasonic.aero] * @version 1.1 * @date 01/27/09 */ public function iterate_visible($print = false) { if ($print) echo \nBRB.$this-get_class_name().::iterateVisible:/BBR\n; $tmp = array(); foreach($this as $key = $value) { $tmp[$key] = $value; if ($print) print $key. = .$value.BR\n; } return $tmp; } And related: /** * Provides generic getters and setters * * @access public * @param string $method The method name. * @param array $arguments The arguments passed to the method. * @return mixed * @author Daevid Vincent [daevid.vinc...@panasonic.aero] * @date 02/02/09 * @see __get(), __set() */ public function __call( $method, $arguments ) { $prefix = strtolower( substr( $method, 0, 3 ) ); $property = strtolower( substr( $method, 4 ) ); if ( empty($prefix) || empty($property) ) return; //exit(__call($method) :: prefix='$prefix' and property='$property'); if ( 'get' == $prefix ) { if ( property_exists($this, $property) ) return $this-$property; else return $this-__get($property); } elseif ( 'set' == $prefix ) { if ( property_exists($this, $property) ) return $this-$property = $arguments[0]; else return $this-__set($property, $arguments[0]); } // Technically we should never get to this point as most calls are get_() or set_() echo pfont color='#ff'Attempted to '.$prefix.-.$method.()' in class '.$this-get_class_name().'./fontp\n; backtrace(); } /** * magic function to handle any accessing of undefined variables. * Since PHP is lax this will help prevent stupid mistakes. * * @access public * @return void * @parammixed $property name of the variable * @author Daevid Vincent [daevid.vinc...@panasonic.aero] * @date 2010-08-12 * @see __set(), __call() */ public function __get($property) { if ($_SESSION['DEVELOPMENT'] !$_SESSION['mobile']) { echo pfont color='#ff'Attempted to __get() non-existant property/variable '.$property.' in class '.$this-get_class_name().'./fontp\n; $this-suggest_alternative($property); backtrace(); exit; } //else exit(__get($property) NO SUCH PROPERTY IN .$this-get_class_name().' CLASS'); //[dv] commented this out as it was obviously exiting on PROD, when really it should just ignore //Throw new BadProperty($this, 'get', $property); } /** * magic function to handle any setting of undefined variables
RE: [PHP] parse_ini_file() seems to be broken in PHP 5.2.4-2ubuntu5.12
-Original Message- From: Tamara Temple [mailto:tamouse.li...@gmail.com] Sent: Thursday, November 11, 2010 1:09 AM To: Daevid Vincent Cc: php-general@lists.php.net Subject: Re: [PHP] parse_ini_file() seems to be broken in PHP 5.2.4-2ubuntu5.12 On Nov 10, 2010, at 8:08 PM, Daevid Vincent wrote: http://php.net/manual/en/function.parse-ini-file.php Why doesn't PHP parse the 'null', 'true', 'false', etc into their proper equivalents? What's worse is that it does this mangling of my RAW values to be strings and sets them to 1 !!! WTF good does that do me?! Here is my test.ini file: -- - --- [examples] ; this is a section ; this is a comment line log_level = E_ALL ~E_NOTICE 1 = intkey ; this is a int key nullvalue = null; this is NULL truebool = true ; this is boolean (TRUE) falsebool = false ; this is boolean (FALSE) intvalue = -1 ; this is a integer (-1) floatvalue = +1.4E-3; this is a float (0.0014) stringvalue = Hello World ; this is a unquoted string quoted = Hello World ; this is a quoted string apostrophed = 'Hello World' ; this is a apostrophed string quoted escaped = it work's \fine\! ; this is a quoted string with escaped quotes apostrophed escaped = 'it work\'s fine!' ; this is a apostrophed string with escaped apostrophes -- - --- Here is my test.php page: -- - --- ?php var_dump(parse_ini_file('./test.ini', true)); ? -- - --- Here is the output: -- - --- array 'examples' = array 'log_level' = string '6135' (length=4) 1 = string 'intkey' (length=6) 'nullvalue' = string '' (length=0) 'truebool' = string '1' (length=1) 'falsebool' = string '' (length=0) 'intvalue' = string '-1' (length=2) 'floatvalue' = string '+1.4E-3' (length=7) 'stringvalue' = string 'Hello World' (length=11) 'quoted' = string 'Hello World' (length=11) 'apostrophed' = string ''Hello World'' (length=13) 'quoted escaped' = string 'it work's \fine\!' (length=17) 'apostrophed escaped' = string ''it work\'sfine' (length=15) -- - --- develo...@mypse:~$ php -v PHP 5.2.4-2ubuntu5.12 with Suhosin-Patch 0.9.6.2 (cli) (built: Sep 20 2010 13:18:10) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans Maybe I'm missing something, but i thought that's what the constants evaluated to In a sloppy way that is accurate, but not sufficient for my needs. If ($nullvalue) If ($truebool) ... But to be more accurate, $nullvalue != is_null($nullvalue) $truebool != is_bool($truebool) $truebool !== TRUE Etc... There are subtle but significant differences -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] use of ini vs include file for configuration
-Original Message- From: Tamara Temple [mailto:tamouse.li...@gmail.com] Sent: Thursday, November 11, 2010 11:04 AM To: PHP General Subject: [PHP] use of ini vs include file for configuration I'm curious what the lists' opinions are regarding the use of an .ini file versus an include configuration file in PHP code are? I can see uses for either (or both). To me, it seems that an .ini file would be ideal in the case where you want to allow a simpler interface for people installing your app to configure things that need configuring, and an included PHP code configuration file for things you don't necessarily want the average installer to change. What do you think? Tamara We used config.inc.php for the past few years, but as our project is grown and we have several other departments developing portions in several different languages (not JUST PHP) but all wanting to share resources such as database connection information, pathing, email addresses (for error reporting, notifications, etc.), memcache servers, etc. using a PHP file is not an option. It can be a shim however and that's what I've done over the past few days is to parse the .ini and populate the same config.inc.php file with said values so that all the code continues to work. Plus it allows for easy populating in a programatic way if you name your variables right and organize things. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: use of ini vs include file for configuration
-Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Thursday, November 11, 2010 11:46 AM To: Jo?o C?ndido de Souza Neto Cc: php-general@lists.php.net Subject: Re: [PHP] Re: use of ini vs include file for configuration On Thu, 2010-11-11 at 17:16 -0200, Jo?o C?ndido de Souza Neto wrote: Agreed. -- Joo Cndido de Souza Neto Tamara Temple tamouse.li...@gmail.com escreveu na mensagem news:977f087c-bb11--b851-21616ae9e...@gmail.com... I'm curious what the lists' opinions are regarding the use of an .ini file versus an include configuration file in PHP code are? I can see uses for either (or both). To me, it seems that an .ini file would be ideal in the case where you want to allow a simpler interface for people installing your app to configure things that need configuring, and an included PHP code configuration file for things you don't necessarily want the average installer to change. What do you think? Tamara There are potential security concerns involved too. An .ini file will be output as plain text by default by the web server if requested by a user agent unless it is protected somehow (by a .htaccess file for example) or it is outside of document root for the server. A PHP file on the other hand will be parsed, so won't output it's variables. It's all too easy to forget to protect an ini file from this sort of thing, whereas if you've written a website in PHP, it becomes fairly evident if your web server isn't configured for PHP without testing specifically for it! Why would you put your configuration file in a ../htdocs folder? That's just poor design. Just as your classes and include files are OUTSIDE your document root, so must your config file be. Plus it's trivial to secure a .ini with a .htaccess or other apache method. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How do I convert the string E_ALL ~E_NOTICE to the decimal equivalent 6135?
-Original Message- From: Ford, Mike [mailto:m.f...@leedsmet.ac.uk] Sent: Thursday, November 11, 2010 12:58 AM To: php-general@lists.php.net Subject: RE: [PHP] How do I convert the string E_ALL ~E_NOTICE to the decimal equivalent 6135? -Original Message- From: Daevid Vincent [mailto:dae...@daevid.com] Sent: 11 November 2010 04:06 To: php-general@lists.php.net We're trying to move all of our configuration files for our DEV/TEST/PROD and various python scripts and such that all need the same DB connection parameters and pathing information to a common and simple config.ini file they all can share across languages. One snag I ran into is this: [dart] relative_url= /dart2 absolute_path = /home/www/dart2 log_level = E_ALL ~E_NOTICE But when I read it in from the file, it's a string (of course) That's odd -- parse_ini_file() should definitely translate those constants! It certainly works on my v5.2.5 installation. Cheers! Mike You assume I'm using that busted-ass parse_ini_file() function. ;-) See previous emails as to why that's a useless option for me. I wrote a much better parser which I'll post in another email. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: a better ini parser WAS: parse_ini_file() seems to be broken in PHP 5.2.4-2ubuntu5.12
Since the default ini parser is pretty much useless because it doesn't convert null/true/false values, nor convert integers/numbers, nor handle all the ; comment styles (inline for example), nor trim extra white space, and the list goes on and on... I wrote a better one -- here's the first stab at it. I'm sure I'll improve it as needed, but you're free to use as you like and hopefully it will save someone else the pain and wasted effort on parse_ini_file(): ?php /** * INI file parser * * @author Daevid Vincent dae...@daevid.com * @dateCreated: 2010-11-09 */ class IniParser { private $file; public $ini_array; /** * Constructor and acts as a singleton for the same $file * * @access public * @return object * @paramstring $file the .ini file to load with full path * @paramboolean $process_sections (true) return a multi-hash broken down by sections * @paramboolean $explode (false) split . keys into sub-array elements * @author Daevid Vincent [dae...@daevid.com] * @date 2010-11-09 */ function __construct($file, $process_sections=true, $explode=false) { if ($_SESSION['INI_PARSER'][$file]) { //echo using pre-made versionbr; return $_SESSION['INI_PARSER'][$file]; } $this-file = $file; //[dv] okay so parse_ini_file() is basically a USELESS POS // not only does it NOT convert true/false/null to proper equivalents, but it mangles the values to be 1(strings) // verified with 5.2.4 to 5.3.3, so not much hope for using this function natively //$this-ini_array = parse_ini_file($file,$process_sections); $this-ini_array = $this-read_ini_file($file); $this-transpose_ini(); if ($explode) $this-explode_ini(); //TODO: handle the 'embrace extend' functionality that Zend Framework provides with the [section : section] format //echo using new versionbr; $_SESSION['INI_PARSER'][$file] = $this; return $this; } private function read_ini_file($file) { $handle = @fopen($file, r); if (!$handle) throw new Exception('Cannot open INI file '.$file); $contents = @fread($handle, filesize($file)); if (!$contents) throw new Exception('Cannot read INI file '.$file); $section = ''; $contents = split(\n, trim($contents)); foreach ($contents as $k = $line) { $line = trim($line); if (!$line) continue; if (in_array($line[0], array(';','#'))) continue; if ($line[0] == [) { preg_match('/\[(.*)\]/', $line, $pmatches); $section = $pmatches[1]; } else { $keyval = explode('=', $line); $tmp = explode(';',$keyval[1]); $mykey = trim($keyval[0]); $myval = trim($tmp[0]); if (substr($mykey, -2) == '[]') //check for arrays $ini_file[$section][substr($mykey, 0, -2)][] = $myval; else $ini_file[$section][$mykey] = $myval; } } @fclose($handle); return $ini_file; } private function transpose_ini() { foreach($this-ini_array as $heading = $key_vals) { foreach ($key_vals as $k = $v) { //echo $k = $vbr\n; if (is_numeric($v)) { $i = intval($v); if ($i == $v) $v = $i; } else switch (strtolower($v)) { case 'true': $v = true; break; case 'false': $v = false; break; case 'null': $v = null; break; } } } } /* * not used currently, but took a while to get this working so keep for future reference/use public function explode_ini() { $ini_array = array(); foreach($this-ini_array as $heading = $key_vals) { foreach ($key_vals as $k = $v) { $path = 'ini_array
[PHP] parse_ini_file() seems to be broken in PHP 5.2.4-2ubuntu5.12
http://php.net/manual/en/function.parse-ini-file.php Why doesn't PHP parse the 'null', 'true', 'false', etc into their proper equivalents? What's worse is that it does this mangling of my RAW values to be strings and sets them to 1 !!! WTF good does that do me?! Here is my test.ini file: --- --- [examples] ; this is a section ; this is a comment line log_level = E_ALL ~E_NOTICE 1 = intkey ; this is a int key nullvalue = null; this is NULL truebool = true ; this is boolean (TRUE) falsebool = false ; this is boolean (FALSE) intvalue = -1 ; this is a integer (-1) floatvalue = +1.4E-3; this is a float (0.0014) stringvalue = Hello World ; this is a unquoted string quoted = Hello World ; this is a quoted string apostrophed = 'Hello World' ; this is a apostrophed string quoted escaped = it work's \fine\! ; this is a quoted string with escaped quotes apostrophed escaped = 'it work\'s fine!' ; this is a apostrophed string with escaped apostrophes --- --- Here is my test.php page: --- --- ?php var_dump(parse_ini_file('./test.ini', true)); ? --- --- Here is the output: --- --- array 'examples' = array 'log_level' = string '6135' (length=4) 1 = string 'intkey' (length=6) 'nullvalue' = string '' (length=0) 'truebool' = string '1' (length=1) 'falsebool' = string '' (length=0) 'intvalue' = string '-1' (length=2) 'floatvalue' = string '+1.4E-3' (length=7) 'stringvalue' = string 'Hello World' (length=11) 'quoted' = string 'Hello World' (length=11) 'apostrophed' = string ''Hello World'' (length=13) 'quoted escaped' = string 'it work's \fine\!' (length=17) 'apostrophed escaped' = string ''it work\'sfine' (length=15) --- --- develo...@mypse:~$ php -v PHP 5.2.4-2ubuntu5.12 with Suhosin-Patch 0.9.6.2 (cli) (built: Sep 20 2010 13:18:10) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How do I convert the string E_ALL ~E_NOTICE to the decimal equivalent 6135?
We're trying to move all of our configuration files for our DEV/TEST/PROD and various python scripts and such that all need the same DB connection parameters and pathing information to a common and simple config.ini file they all can share across languages. One snag I ran into is this: [dart] relative_url= /dart2 absolute_path = /home/www/dart2 log_level = E_ALL ~E_NOTICE But when I read it in from the file, it's a string (of course) $log_level_string = E_ALL ~E_NOTICE; echo 'log level string = '.eval($log_level_string.';').'br'; This gives me nothing!: log level string = Wheras this one gives the proper values: echo 'log bit level = '.(E_ALL ~E_NOTICE).'br'; Output is: log bit level = 6135 But that defeats the purpose of a config file. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Zend studio location Cross-Domain Scripting Vulnerability
-Original Message- From: Thijs Lensselink [mailto:d...@lenss.nl] Sent: Tuesday, October 12, 2010 9:26 PM To: php-general@lists.php.net Subject: Re: [PHP] Zend studio location Cross-Domain Scripting Vulnerability On 10/13/2010 12:19 AM, Daevid Vincent wrote: http://80vul.com/Zend%20studio/Zend%20studio%20location%20Cross.htm Interesting. A co-worker and I were JUST noticing how our PHPDoc comments were being parsed pretty much verbatim includingb tags and links and stuff and thought, wow, that's stupid, that's just a XSS or injection waiting to happen. LOL. Guess someone's ears were burning. ;-) Why didn't you inform Zend before you went full disclosure? It's a nasty bug though!! You misunderstand. *I* did not write that web page. It was just coincidence that *I* encountered the same thing the other day and then someone on Reddit posted that URL. That's all. Timing. Thought I'd share with the PHP community here though since many of us use Zend (and perhaps PDT and Aptana have the same issue?) d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] poll of 'public framework or roll your own'
That was my poll! :) Do you use a public framework or roll your own? I personally find most frameworks to be either too generic or too restricting. To do some tasks you have to jump through many hoops. I see the benefit and certainly for prototypes they may have use, but I tend to find that building a custom framework using some basic tools like a DB wrapper, debug routines, selectbox routines, dynamic menu creation, headers, footers, etc. gives all the MVC power I need. What do you do? What's a framework? 1 (1.9%) I don't use any framework (by choice or policy). 9 (16.7%) I use my own custom framework. 33 (61.1%) I use a public framework like Zend, Symfony, Cake, etc. 11 (20.4% P.s. the link works fine for me... http://www.rapidpoll.net/8opnt1e And here are two more of interest maybe: http://www.rapidpoll.net/show.aspx?id=awp1ocy http://www.rapidpoll.net/show.aspx?id=arc1opy -Original Message- From: Tommy Pham [mailto:tommy...@gmail.com] Sent: Friday, October 08, 2010 6:47 AM To: PHP Subject: [PHP] poll of 'public framework or roll your own' Hi, Does anyone know/remember what's the results of that old poll back in mid(?) January? http://marc.info/?l=php-generalm=126455173203450w=2 I can't seem to access http://www.rapidpoll.net/8opnt1e. Thanks, Tommy -- 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] Zend studio location Cross-Domain Scripting Vulnerability
http://80vul.com/Zend%20studio/Zend%20studio%20location%20Cross.htm Interesting. A co-worker and I were JUST noticing how our PHPDoc comments were being parsed pretty much verbatim including b tags and links and stuff and thought, wow, that's stupid, that's just a XSS or injection waiting to happen. LOL. Guess someone's ears were burning. ;-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] 1984 (Big Brother)
-Original Message- From: tedd [mailto:t...@sperling.com] Sent: Sunday, September 12, 2010 9:32 AM To: PHP-General list Subject: [PHP] 1984 (Big Brother) Hi gang: I have a client who wants his employees' access to their online business database restricted to only times when he is logged on. (Don't ask why) In other words, when the boss is not logged on, then his employees cannot access the business database in any fashion whatsoever including checking to see if the boss is logged on, or not. No access whatsoever! Normally, I would just set up a field in the database and have that set to yes or no as to if the employees could access the database, or not. But in this case, the boss does not want even that type of access to the database permitted. Repeat -- No access whatsoever! I was thinking of the boss' script writing to a file that accomplished the yes or no thing, but if the boss did not log off properly then the file would remain in the yes state allowing employees undesired access. That would not be acceptable. So, what methods would you suggest? Cheers, tedd You sure know how to pick'em Tedd. This is the second whacky client you've posted about on the list... This guy sounds like a real control-freak (read: tool). One other thing I'll throw out is the use of a crontab to start/stop mysql during boss's hours. I don't have a complete solution for you as I just don't care enough about helping this Dbag lord over his employees like that, but I suspect you could have /etc/init.d/mysql start or stop at some pre-determined times like 8am - noon. Then noon till 5pm. Or something. RDBMS are not really designed to be turned on and off like that. Another option is to maybe use M$ Access instead (which does have a multi-user mode). Use ODBC to connect via PHP to it. So then he would start up the DB when he likes and shut it down when he likes. (note that a logout of Windows will NOT prevent the ODBC connection as it is a service -- as God intended RDBMS to be) http://www.configure-all.com/php_access.php This guy is making me angry just thinking about it! d -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 1984 (Big Brother)
have been you'll have fun getting paid to re-do everything. Having everything require a usb stick to launch sounds secure, until he loses the stick or forgets it at home one day. For fun I'd suggest tagging ...or pulls it out before all the writes have taken place from the cache or mysql's DELAYED WRITES and so the DB is corrupt or lost integrity. *sigh* -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Zend framework
http://www.php.net/manual/en/language.oop5.basic.php -Original Message- From: David Harkness [mailto:davi...@highgearmedia.com] Sent: Friday, September 10, 2010 10:59 AM To: rquadl...@googlemail.com Cc: chris h; PHP-General Subject: Re: [PHP] Zend framework We use part of Zend MVC (the dispatcher, controllers, and view scripts) here and a lot of the other facilities such as the autoloader, config, etc. and are very happy so far. As long as you design your application with an eye toward portability, you won't be tied to ZF. For example, put all of your business logic in model classes instead of the controllers themselves. That way if you ever need to move to a new presentation layer or use the business logic outside it (e.g. in SOAP or RPC messages), you'll be ready. David -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Zend framework
Sorry wrong thread. Damnit. I meant that link for the guy that didn't know what the - was for... -Original Message- From: Daevid Vincent [mailto:dae...@daevid.com] Sent: Friday, September 10, 2010 12:01 PM To: 'David Harkness' Cc: 'PHP-General' Subject: RE: [PHP] Zend framework http://www.php.net/manual/en/language.oop5.basic.php -Original Message- From: David Harkness [mailto:davi...@highgearmedia.com] Sent: Friday, September 10, 2010 10:59 AM To: rquadl...@googlemail.com Cc: chris h; PHP-General Subject: Re: [PHP] Zend framework We use part of Zend MVC (the dispatcher, controllers, and view scripts) here and a lot of the other facilities such as the autoloader, config, etc. and are very happy so far. As long as you design your application with an eye toward portability, you won't be tied to ZF. For example, put all of your business logic in model classes instead of the controllers themselves. That way if you ever need to move to a new presentation layer or use the business logic outside it (e.g. in SOAP or RPC messages), you'll be ready. David -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Making multiple RSS feeds for the blog website
-Original Message- From: Andre Polykanine [mailto:an...@oire.org] Sent: Thursday, August 26, 2010 4:53 PM To: php-general Subject: [PHP] Making multiple RSS feeds for the blog website Hi everyone, We are developing a blog service website. What we need now is the ability to make multiple RSS feeds from several pages (an RSS of each user's blog, a feed from each timeline - timelines are our representation of users' favorites; a feed filled with comments to a separate entry, etc.). What would be great is the following: a user enters, say, in my blog and sees the mark that there are RSS feeds. Then he/she clicks the mark or presses a keystroke (Alt+J in IE8, for instance), finds the feed and double-clicks on it. Then he/she can either read the feed or subscribe to it. The feeds have usually file extensions of .rss or .xml. Question: how do we do that with PHP? Thanks! -- With best regards from Ukraine, Andre Skype: Francophile Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com/menelion In otherwords, to paraphrase: DBAG_MODE We have this super cool new idea that's going to revolutionize the web and blogs and cloud computing and we might even create our own new buzzword. We heard you can do this with PHP. We just don't have any code written, so could you guys write it for us. That'd be swell. kthxbye. ;-) Dude. Andre. Let me break it down like a fraction, as to how this list works. YOU post some code that you are struggling with, or you post some SPECIFIC question, and the generous subscribers to this list decide if your question is worthy of their time to reply. Your question (for lack of a better term) was devoid of either of those things. Now, had you said, How can I formulate an RSS feed?, I might point you to this: http://www.phpclasses.org/package/560-PHP-XML-RSS-feed-generator-for-conten t-syndication-.html Or if you had said, How does one double click? (since that is NOT a web-friendly navigation method by default), I might point you in this direction: script onload = function () { document.getElementById(textarea).ondblclick = function () { alert('Double Clicked!') } } /script then this in the body textarea id=textarea/textarea Or even if you said, How do I steal, er um, read an XML file from another site? Then someone might show you these functions (since you clearly missed them when you RTFPM) http://us2.php.net/manual/en/function.file-get-contents.php http://us2.php.net/manual/en/ref.simplexml.php http://us2.php.net/manual/en/book.dom.php But again, your question was so vague that I (and everyone else) probably has nowhere to begin to help you and therefore most likely won't. Given the above advice, you might consider breaking your questions down into PHP related specific examples. /DBAG_MODE -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Can't read $_POST array
You've got something jacked. DO NOT proceed with your coding using this hack. Put this in a blank file named whatever_you_want.php and hit it with your web browser. --- - ?php if ($_POST['action'] == 'Go') print_r($_POST); ? form action=?=$_SERVER['SCRIPT_NAME']? method=POST select name=my_select option value=foofoo/option option value=barbar/option /select input type=submit value=Go name=action class=button submit/ /form --- - -Original Message- From: Brian Dunning [mailto:br...@briandunning.com] Sent: Wednesday, August 18, 2010 2:23 PM To: PHP-General Subject: Re: [PHP] Can't read $_POST array This was the complete code of the page (this is the POST version not the REQUEST version): ?php $response = print_r($_POST, true); echo $response; ? Returns an empty array no matter what POST vars are sent. We fixed it by changing it to this, which I've never even heard of, but so far is working perfectly: ?php $response = file_get_contents('php://input'); echo $response; ? I have no idea what the problem was. Thanks to everyone for your help. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ?php if ($_POST['action'] == 'Go') print_r($_POST); ? form action=?=$_SERVER['SCRIPT_NAME']? method=POST select name=my_select option value=foofoo/option option value=barbar/option /select input type=submit value=Go name=action class=button submit/ /form -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] It's Friday (a MySQL Question)
-Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Friday, August 13, 2010 3:00 PM To: tedd Cc: php-general@lists.php.net Subject: Re: [PHP] It's Friday (a MySQL Question) On Fri, 2010-08-13 at 17:48 -0400, tedd wrote: Hi gang: Normally if I want to dump a MySQL database, I read the database via a PHP script (i.e., list tables and fetch rows) and save the results as a text file -- after which I download the file -- it's not a big deal. However while I was doing my daily read of the MySQL Manual, namely: http://dev.mysql.com/doc/refman/5.0/en/select.html I came across this statement: SELECT * FROM table_reference INTO OUTFILE 'file_name' It looked to be bit simpler/shorter than my code, so I tried it. But it reports: Access denied for user 'me'@'localhost' (using password: YES). I suspect that the access being denied is because MySQL doesn't have permission to create the output file. The MySQL manual reports: 1) that a file cannot be present; 2) AND MySQL must have file privileges to create the file -- but I don't know how to set that up. http://dev.mysql.com/doc/refman/5.0/en/grant.html http://dev.mysql.com/doc/refman/5.0/en/privileges-provided.html#priv_file GRANT SELECT, FILE ON mydb.table_reference TO 'me'@'localhost'; I've only ever done something like this via the command line. Having said that, could you maybe pass a command line string to exec(). Something like (untested): echo 'password' | mysql -u root -p query You know you can pass that on the command line right and avoid this pipe business? mysql -uroot -ppassword query Or mysql --user=root --password=password query I believe that is the right sort of thing, but I've never quite done it all as a single statement like this before, I've always tended to type in things on a line-by-line basis. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] It's Friday (a MySQL Question)
-Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Friday, August 13, 2010 3:23 PM To: Daniel P. Brown Cc: tedd; php-general@lists.php.net Subject: Re: [PHP] It's Friday (a MySQL Question) On Fri, 2010-08-13 at 18:22 -0400, Daniel P. Brown wrote: On Fri, Aug 13, 2010 at 18:17, Ashley Sheridan a...@ashleysheridan.co.uk wrote: To both David and Daniel, thank you! How on earth I ever missed that argument before is a wonder known only to the great electronic deity in the sky! Hey, Daevid: you may have been thanked first, but at least my name was spelled correctly. Sorry Daevid, blame it on the wine I've been drinking! It is a Friday after all! For the amount of crap I stir up on this list, having my name misspelled is a slight penance. ;-p -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Storing Social Security Number WAS: Encryption/Decryption Question
-Original Message- From: tedd [mailto:t...@sperling.com] Sent: Thursday, August 12, 2010 8:32 AM To: Bastien Koert Cc: php-general@lists.php.net Subject: Re: [PHP] Storing Social Security Number WAS: Encryption/Decryption Question For searching standard fields, it's a piece of cake to use %LIKE%. For example, let's say the investigator has a piece of paper that has the number 393 on it and want's to search the database for all phone numbers that contain 393 -- he could use %LIKE% and that would produce 517-393-, 393-123-4567, 818-122-4393 and so on. That's neat! However, if the field is encrypted, then how do you preform a partial search on that? You can't encrypt the search string and use that because you need the entire string. So, how do you solve that problem? If you hash the number of store the hash, then you can create a hashed search string and use that. But again it doesn't work for partial %LIKE% searches. For example, I couldn't search for 393 in a SS# -- I would have to search for the complete SS#. So, how do you solve the %LIKE% problem with encryption and hashes? Well, if you can get all the encryption/decryption to take place in SQL, you can use something like this pseudocode: SELECT name, dob, DECRYPT(ssn) as rawssn FROM deadbeats HAVING rawssn LIKE '%393%'; You can assign an alias and use HAVING instead of WHERE. http://dev.mysql.com/doc/refman/5.0/en/select.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP The Anthem
http://www.youtube.com/watch?v=S8zhmiS-1kw http://shiflett.org/blog/2010/aug/php-anthem ...some people have way too much time. ;-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] eval and HEREDOC
-Original Message- From: Sorin Buturugeanu [mailto:m...@soin.ro] Sent: Tuesday, July 20, 2010 2:11 PM To: php-general@lists.php.net Subject: [PHP] eval and HEREDOC Hello, I am having trouble with a part of my templating script. I'll try to explain: The template itself is HTML with PHP code inside it, like: div?=strtoupper($user['name']);?/div And I have the following code as part of the templating engine: $template = file_get_contents($file); $template = return TEMPLATE\n.$template.\nTEMPLATE;\n; $template = eval($template); The problem is that the eval() HEREDOC combination gives the following output: ?=strtoupper(Array['time']);? If in the HTML file (template) I use div?=strtoupper({$user['name']});?/div I get ?=strtoupper(username);? as an output. I have tried closing the php tag like this: $template = return TEMPLATE\n?.$template.\nTEMPLATE;\n; but the extra ? only gets outputed as HTML. This is my first post to this mailing list, so I great you all and thank you for any kind of solution to my problem. Why are you using HEREDOC to begin with? I personally find them to be ugly and more trouble than they're worth. You can write the same thing as this I think (untested): $template = eval(file_get_contents($file)); But you might also consider using include_once or require_once instead of this eval() business. Also note, that a string can span more than one line and have variables in it. It can even be used with code, so HEREDOC is again useless for most situations: $foo = Hello $name,\n \n Today is .date('Y-m-d').\n \n Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n Nulla eros purus, pharetra a blandit non, pellentesque et leo. In augue metus, mattis a sollicitudin in, placerat vitae elit. \n Quisque elit mauris, varius sit amet cursus sed, eleifend a mauris. ; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Serial Numbers
-Original Message- From: Gary [mailto:gp...@paulgdesigns.com] Sent: Monday, July 12, 2010 11:53 AM I'm sure it is possible, but I am unsure how to do this. I have created a Sale coupon that I was going to put up on a site that I manage, for visitors to print out and bring to the store. The coupon is currently a .png, however I was planning on converting to a pdf. I would like to put on the coupon a serial number that increases by 1 everytime the page is viewed. I dont really care if someone refreshes the page and skews the numbers. Is this possible and could someone give me some help? Is there a reason you need to increment by 1? I mean, are you going to validate the coupon someone brings in to see if it's in the database or is used already? Since you say you don't care if the number is skewed, it sounds as if you don't care about the code either really. Point being, why not just use md5(time()) or uniqid() or something and make some truly unique code (that you may or may not wish to store in a DB). This will be obscure enough the average person won't know that it isn't tracked and most likely won't try to make their own. If I saw 123457, I'm pretty sure I could make a coupon with 123500 on it. But if I saw 6ccd780c-baba-1026-9564-0040f4311e29 then I'm not really going to try and fudge one of those. Then I'd use the barcode library to print the code (again, doesn't have to actually work if you're not going to do a lookup) just to add more realizm to it. There are a billion different ways to make a unique ID. Even IF you are going to track them, you really shouldn't do a sequential code as you originally wanted to do. http://us.php.net/manual/en/function.uniqid.php http://php.net/manual/en/function.com-create-guid.php http://us.php.net/manual/en/function.mssql-guid-string.php http://us.php.net/manual/en/function.md5.php http://us.php.net/manual/en/function.sha1.php http://us.php.net/manual/en/function.hash.php http://us.php.net/manual/en/function.time.php http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#functio n_uuid Heck, you could even just use ip2long() on their IP address and then when someone redeems the coupon code, a simple long2ip() would tell you if it's a valid IP format rather than some hacked up string. http://us.php.net/manual/en/function.ip2long.php http://us.php.net/manual/en/function.long2ip.php Daevid. http://daevid.com Some people, when confronted with a problem, think 'I know, I'll use XML.' Now they have two problems. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Creating image on-the-fly
-Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Wednesday, July 07, 2010 1:22 PM To: Marc Guay Cc: php-general Subject: Re: [PHP] Creating image on-the-fly On Wed, 2010-07-07 at 16:05 -0400, Marc Guay wrote: I was wondering if there was any way I can create an image from some text with php? Something like this? http://sgss.me/obsolete/experiments/phpfontimagegenerator2/usage.php One thing to bear in mind is that this introduces extra server load if the image is generated dynamically for each visit to a page. It's best to save the image once it's first created and use that file if it exists the next time round. Thanks, Ash http://www.ashleysheridan.co.uk Some folks call this a cache ;-) http://en.wikipedia.org/wiki/Cache -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] file_get_contents limit
-Original Message- From: Andrew Ballard [mailto:aball...@gmail.com] Sent: Tuesday, June 29, 2010 1:56 PM To: a...@ashleysheridan.co.uk Cc: Jo?o C?ndido de Souza Neto; php-general@lists.php.net Subject: Re: [PHP] file_get_contents limit On Tue, Jun 29, 2010 at 4:39 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Tue, 2010-06-29 at 16:37 -0400, Andrew Ballard wrote: On Tue, Jun 29, 2010 at 4:21 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: Have you looked at the memory settings in php.ini? I doubt that is the cause, at least not by itself. 21504 characters is only 21K of data (could be more if the characters are multi-byte encoded, but still less than 100K) , and the default memory limit in PHP is 128M. I'm not sure what else it could be, though, as I don't see any limitations on file_get_contents() discussed in the manual. Default memory limit is still 32MB on every default install I've seen. The manual currently shows 128M, and that's what I've seen for some time now. Even so, a function returning less than 100K shouldn't exhaust 32M of memory either, unless something else is at play. If there is a memory limit being reached, PHP should log either an error or warning (I can't remember which). Maybe try to specify the number of $maxlen bytes to read? http://us4.php.net/file_get_contents string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen = -1 ) You could also do it the faster and old fashioned way: $fh = fopen('/tmp/test.zip', 'r'); $data = fread($fh, filesize('/tmp/test.zip')); fclose($fh); Or if it's multibyte maybe try this: function file_get_contents_utf8($fn) { $content = file_get_contents($fn); return mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true)); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php