php-general Digest 28 Oct 2011 08:18:47 -0000 Issue 7541
php-general Digest 28 Oct 2011 08:18:47 - Issue 7541 Topics (messages 315456 through 315480): Re: Exporting large data from mysql to html using php 315456 by: Jim Giner 315467 by: Jason Pruim 315468 by: Jason Pruim Question reading a file 315457 by: Tedd Sperling 315461 by: Ashley Sheridan 315463 by: Daniel Brown 315464 by: Tedd Sperling Execute permission question 315458 by: Tedd Sperling 315459 by: Larry Martell 315460 by: Ashley Sheridan 315465 by: Tedd Sperling 315466 by: Daniel Brown 315469 by: Tedd Sperling 315470 by: Tedd Sperling 315471 by: Daniel Brown OpenId Provider 315462 by: Roy Kaldung 315475 by: Negin Nickparsa Help with redeclare error 315472 by: Jack 315473 by: Jason Pruim 315474 by: Daniel Brown 315476 by: UltraMega Admin 315478 by: Ashley Sheridan Re: array_unique by id multi-dimensional array 315477 by: tamouse mailing lists 315479 by: Tontonq Tontonq 315480 by: sivaji j.g Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- Good luck, that's a LOT of reading. I'd estimate that's about 3k+ pages of reading. :) Regards, Tommy nice to see someone else is finally getting the point that I'm been making. ---End Message--- ---BeginMessage--- Jason Pruim li...@pruimphotography.com On Oct 27, 2011, at 2:44 PM, Tommy Pham wrote: On Wed, Oct 26, 2011 at 5:47 PM, Jason Pruim li...@pruimphotography.com wrote: Jason Pruim li...@pruimphotography.com The server that's running it is a home computer with a VPS installed... It's not my dev environment :) Home computer used for a production environment? Wow.. I'm speechless. Ummm... No... Home computer for a dev environment... The final product will be moved to a better host. This is temporary... And actually isn't a bad idea... If you get it running good on a cheap home computer, why wouldn't it run *BETTER* on the high-end production server? The information being searched is specifically phone numbers, and the bosses want to provide the public away to browse them, hence the pagination... Once I removed a COUNT from mysql it started working alot better... So I still need to provide a better pagination system, but it's working. If just showing phone numbers only and no other information, what's the point since there are already several other white and yellow pages on the net? There's even a reverse number look-up too. There's also a well known paid service for getting a DB of contacts (name, address, phone numbers of persons and businesses). Just out of curiosity, what is it that your boss intend to offer that would stand out for already existing services? I doubt anyone would be sane enough to sit there and just browse through phone numbers only. Even if it does show the owner's name of the registered number, I highly doubt anyone sane would browse unless you provide some kind of filter/search. I'm not expecting people to look at every single page... But I need away to allow curious people the ability to page through results if they want. Oh, and the 89 million is just for one state :) We are talking the possibility of I believe 10 billion numbers to cover the US, not to mention Canada which I believe uses the same numbering system as we do so that could be another 10 billion... As I've mentioned, something of this magnitude is better to leave it to the DBA and work together with that DBA. Either hire/contract one or become one :) I'm working on becoming one ontop of web designer and programmer :) Good luck, that's a LOT of reading. I'd estimate that's about 3k+ pages of reading. :) I've always been a fan of reading :) Just wish I had more time to do it! :) ---End Message--- ---BeginMessage--- Jason Pruim li...@pruimphotography.com On Oct 27, 2011, at 4:08 PM, Nathan Nobbe wrote: On Mon, Oct 24, 2011 at 6:50 PM, Jason Pruim li...@pruimphotography.com wrote: Now that I've managed to list 3 separate programming languages and somewhat tie it back into php here's the question... I have about 89 million records in mysql... the initial load of the page takes 2 to 3 minutes, I am using pagination, so I have LIMIT's on the SQL query's... But they just aren't going fast enough... What I would like to do, is pull the data out of MySQL and store it in the HTML files, and then update the HTML files once a day/week/month... I can figure most of it out... BUT... How do I automatically link to the
Re: [PHP] Help with redeclare error
On Thu, 2011-10-27 at 17:40 -0700, UltraMega Admin wrote: On 10/27/2011 5:33 PM, Daniel Brown wrote: On Thu, Oct 27, 2011 at 20:06, Jason Pruimli...@pruimphotography.com wrote: Most likely you have in included in 2 files... Look into it from that angle... It only needs to be included in 1 file to work throughout all the files. Prune is spot-on. That error generally happens when you include a file that has already been included, which contains function definitions. Look at the code in the files the error mentions, on the lines it specifies, and - most likely - you'll see an include. Changing them to include_once instead will resolve the issue, as PHP will just skip the order if it's already been done within the execution of the code. A function with that name already exists in PHP as of 5.3.0. You'll have to rename it or something. http://us2.php.net/manual/en/function.date-diff.php Or wrap it inside a function_exists() call assuming that both your function and the internal one do the same thing. -- Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] array_unique by id multi-dimensional array
let me explain again this is my array Array ( [0] = Array ( [likes] = 137846 [name] = blabla [access_token] = AAABZBD [id] = 157644197612598 [link] = http://www.facebook.com/blabla ) [1] = Array ( [likes] = 137698 [name] = blabla [access_token] = AAAnnL [id] = 157644197612598 [link] = http://www.facebook.com/blabla ) [2] = Array ( [likes] = 134391 [name] = sieaq [access_token] = AAA04 [id] = 163744743683729 [link] = http://www.facebook.com/zart ) [3] = Array ( [name] = defolaq [access_token] = AAAZD [id] = 139820007610 [link] = http://www.facebook.com/apps/application.php?id=239820007640 [likes] = 0 ) [4] = Array ( [name] = falan [access_token] = AAW4NNGAZDZD [id] = 374971333999 [link] = http://www.facebook.com/apps/application.php?id=37495199 [likes] = 0 ) [5] = Array ( [name] = filan [access_token] = AAABZCTCw [id] = 237184173662497 [link] = http://www.facebook.com/pages/filan/237184173662497 [likes] = 0 ) [6] = Array ( [name] = bigit [access_token] = Jj77twGFvS8YyB [id] = 10497735291210 [link] = http://www.facebook.com/pages/bigit/10497735291210 [likes] = 0 ) ) but as you see there are 2 sub array with [id] = 157644197612598 i want to delete sub arrays repeated with same id.? 2011/10/28 tamouse mailing lists tamouse.li...@gmail.com On Thu, Oct 27, 2011 at 10:31 AM, Tontonq Tontonq root...@gmail.com wrote: i have an array like [0] = Array ( [likes] = 113091 [name] = blabla [access_token] = AAABZCTx [id] = 188206217874932 ) [1] = Array ( [likes] = 113091 [name] = blabla [access_token] = AAABZCTz [id] = 188206217874932 ) i want to filter the array by [id] sub value? Not quite sure what you mean by filter in this case, but the function that pops to mind is http://www.php.net/manual/en/function.array-filter.php, which applies a callback function to each member of the array where you can determine if it should be included in the filtered list by returning true.
Re: [PHP] array_unique by id multi-dimensional array
On Fri, Oct 28, 2011 at 1:22 PM, Tontonq Tontonq root...@gmail.com wrote: let me explain again this is my array Array ( [0] = Array ( [likes] = 137846 [name] = blabla [access_token] = AAABZBD [id] = 157644197612598 [link] = http://www.facebook.com/blabla ) [1] = Array ( [likes] = 137698 [name] = blabla [access_token] = AAAnnL [id] = 157644197612598 [link] = http://www.facebook.com/blabla ) [2] = Array ( [likes] = 134391 [name] = sieaq [access_token] = AAA04 [id] = 163744743683729 [link] = http://www.facebook.com/zart ) [3] = Array ( [name] = defolaq [access_token] = AAAZD [id] = 139820007610 [link] = http://www.facebook.com/apps/application.php?id=239820007640 [likes] = 0 ) [4] = Array ( [name] = falan [access_token] = AAW4NNGAZDZD [id] = 374971333999 [link] = http://www.facebook.com/apps/application.php?id=37495199 [likes] = 0 ) [5] = Array ( [name] = filan [access_token] = AAABZCTCw [id] = 237184173662497 [link] = http://www.facebook.com/pages/filan/237184173662497 [likes] = 0 ) [6] = Array ( [name] = bigit [access_token] = Jj77twGFvS8YyB [id] = 10497735291210 [link] = http://www.facebook.com/pages/bigit/10497735291210 [likes] = 0 ) ) but as you see there are 2 sub array with [id] = 157644197612598 i want to delete sub arrays repeated with same id.? If my understanding is right, a simple foreach loop and unset() will do this. Below is the untested version of snippet I would use to remove the duplicate sub arrays, $id = array(); foreach ($items as $key = $item) { if (in_array($item['id'], $id)) { unset($items[$key]); } else { $id[] = $item['id']; } } -- Sivaji http://sivaji.drupalgardens.com @sivaji_ganesh https://twitter.com/#%21/sivaji_ganesh in twitter sivaji2...@gmail.com Gtalk / Skype: sivaji2009
Re: [PHP] array_unique by id multi-dimensional array
thanks it works 2011/10/28 sivaji j.g sivaji2...@gmail.com On Fri, Oct 28, 2011 at 1:22 PM, Tontonq Tontonq root...@gmail.comwrote: let me explain again this is my array Array ( [0] = Array ( [likes] = 137846 [name] = blabla [access_token] = AAABZBD [id] = 157644197612598 [link] = http://www.facebook.com/blabla ) [1] = Array ( [likes] = 137698 [name] = blabla [access_token] = AAAnnL [id] = 157644197612598 [link] = http://www.facebook.com/blabla ) [2] = Array ( [likes] = 134391 [name] = sieaq [access_token] = AAA04 [id] = 163744743683729 [link] = http://www.facebook.com/zart ) [3] = Array ( [name] = defolaq [access_token] = AAAZD [id] = 139820007610 [link] = http://www.facebook.com/apps/application.php?id=239820007640 [likes] = 0 ) [4] = Array ( [name] = falan [access_token] = AAW4NNGAZDZD [id] = 374971333999 [link] = http://www.facebook.com/apps/application.php?id=37495199 [likes] = 0 ) [5] = Array ( [name] = filan [access_token] = AAABZCTCw [id] = 237184173662497 [link] = http://www.facebook.com/pages/filan/237184173662497 [likes] = 0 ) [6] = Array ( [name] = bigit [access_token] = Jj77twGFvS8YyB [id] = 10497735291210 [link] = http://www.facebook.com/pages/bigit/10497735291210 [likes] = 0 ) ) but as you see there are 2 sub array with [id] = 157644197612598 i want to delete sub arrays repeated with same id.? If my understanding is right, a simple foreach loop and unset() will do this. Below is the untested version of snippet I would use to remove the duplicate sub arrays, $id = array(); foreach ($items as $key = $item) { if (in_array($item['id'], $id)) { unset($items[$key]); } else { $id[] = $item['id']; } } -- Sivaji http://sivaji.drupalgardens.com @sivaji_ganesh https://twitter.com/#%21/sivaji_ganesh in twitter sivaji2...@gmail.com Gtalk / Skype: sivaji2009
[PHP] 求正则
http://jingji.cntv.cn/yaowen/20111027.shtml 获取该网站源码的url的php的正 则表达式 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 求正则
在 2011-10-28五的 16:35 +0800,yuxiangye写道: http://jingji.cntv.cn/yaowen/20111027.shtml 获取该网站源码的url的php的正 则表达式 i can not get you clearly. 不懂你的意思~ -- Best regards, Sharl.Jimh.Tsin (From China **Obviously Taiwan INCLUDED**) Using Gmail? Please read this important notice: http://www.fsf.org/campaigns/jstrap/gmail?10073. signature.asc Description: This is a digitally signed message part
Re: [PHP] Friday Distraction
On Thu, Oct 27, 2011 at 10:18 AM, Richard Quadling rquadl...@gmail.comwrote: On 21 October 2011 17:27, Daniel Brown danbr...@php.net wrote: I'll get this week's Friday distraction kicked off here with something shared with me by a Facebook friend. If you're on Facebook, try this. It's pretty sweet (and safe for work and kids). http://www.takethislollipop.com/ Sweet? SWEET!? What sort of sicko are you??? I've got a deranged nutter hunting me down. He looks a LOT like you Cool though. Well, Daniel, I'll bet you never thought that your Friday Distraction would elicit such a broad range of responses AND keep the commentary coming right through to the next Friday. Nice :) Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com
[PHP] want to get Regular Expressions
get the url form the source of http://jingji.cntv.cn/yaowen/20111027.shtml withRegular Expressions. I want to get the Regular Expressions -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] want to get Regular Expressions
yuxiangye yuxian...@gmail.com wrote: get the url form the source of http://jingji.cntv.cn/yaowen/20111027.shtml withRegular Expressions. I want to get the Regular Expressions -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Erm, say what now? I really don't understand what you're trying to do here. Thanks, Ash http://www.ashleysheridan.co.uk -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execute permission question
On Thu, 27 Oct 2011, Tedd Sperling wrote: You answered a question I wasn't prepared to ask, which was How can php scripts be executed when their execute permissions aren't set? Because as far as the system is concerned, the thing which is being executed is either PHP itself or something in which PHP is being run (e.g. Apache). The fact that PHP then loads a script and executes it is not really the point. When used in websites, it's the webserver itself which loads the PHP interpreter which in turn loads the script. So the webserver needs to be executable. The Apache module, for example, does not because Apache loads it into Apache which is already running. If you're not actually running programs on the host itself via a shell, then you probably won't need execute permissions most of the time. Geoff. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Friday Distraction
On Fri, Oct 28, 2011 at 05:03, Adam Richardson simples...@gmail.com wrote: Well, Daniel, I'll bet you never thought that your Friday Distraction would elicit such a broad range of responses AND keep the commentary coming right through to the next Friday. Nice :) This is nothing compared to how it used to be ~2007-08. ;-P -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] want to get Regular Expressions
you want to get which part of the url? On 10/28/11, Ashley Sheridan a...@ashleysheridan.co.uk wrote: yuxiangye yuxian...@gmail.com wrote: get the url form the source of http://jingji.cntv.cn/yaowen/20111027.shtml withRegular Expressions. I want to get the Regular Expressions -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Erm, say what now? I really don't understand what you're trying to do here. Thanks, Ash http://www.ashleysheridan.co.uk -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. -- 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] Friday Distraction
On 28 Oct 2011, at 12:54, Daniel Brown wrote: On Fri, Oct 28, 2011 at 05:03, Adam Richardson simples...@gmail.com wrote: Well, Daniel, I'll bet you never thought that your Friday Distraction would elicit such a broad range of responses AND keep the commentary coming right through to the next Friday. Nice :) This is nothing compared to how it used to be ~2007-08. ;-P Ahh, the good old days! -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Help with redeclare error
A function with that name already exists in PHP as of 5.3.0. You'll have to rename it or something. http://us2.php.net/manual/en/function.date-diff.php That looks like what happened that new function was added and we had written one with the same name from the stone age... Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execute permission question
On Oct 28, 2011, at 7:19 AM, Geoff Shang wrote: On Thu, 27 Oct 2011, Tedd Sperling wrote: You answered a question I wasn't prepared to ask, which was How can php scripts be executed when their execute permissions aren't set? Because as far as the system is concerned, the thing which is being executed is either PHP itself or something in which PHP is being run (e.g. Apache). The fact that PHP then loads a script and executes it is not really the point. When used in websites, it's the webserver itself which loads the PHP interpreter which in turn loads the script. So the webserver needs to be executable. The Apache module, for example, does not because Apache loads it into Apache which is already running. If you're not actually running programs on the host itself via a shell, then you probably won't need execute permissions most of the time. Geoff. Geoff: Thanks -- this is one of those things that normally goes without saying but by doing so remains a question to some. Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execute permission question
On Oct 27, 2011, at 7:49 PM, Daniel Brown wrote: On Thu, Oct 27, 2011 at 19:44, Tedd Sperling tedd.sperl...@gmail.com wrote: One of the things I'm trying to understand is a php script can execute a shell command, right? Is there a way via permissions to prevent that -- or -- does that even have anything to do with it? That's where I'm fuzzy. Sure. What PHP actually does is interface with a forked shell (usually 'sh' by default) process, and the shell then has permission controls and requirements of its own, defined by the operating system's configuration. So PHP isn't actually executing the commands, per se, but is instead instructing the shell to do so itself. To see how to limit PHP's shell access, look into safe_mode and the like. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ Daniel: Thanks. But does having execute permissions set on a script affect the scripts ability to run shell commands? For example, if I have a script that contains a shell command, can I prohibit that script from executing the command by setting it's execute permission to not execute? Certainly, as is my normal custom, I could try it and find out for myself -- but I have always been reluctant to use shell commands. Besides, never having used them, I don't see their advantage yet. Currently, they seem strange and dangerous to me. As always, your insight is welcomed. Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execute permission question
On Fri, Oct 28, 2011 at 11:01, Tedd Sperling tedd.sperl...@gmail.com wrote: But does having execute permissions set on a script affect the scripts ability to run shell commands? Negative. It won't inherit permissions, though one might expect that to make sense. For example, if I have a script that contains a shell command, can I prohibit that script from executing the command by setting it's execute permission to not execute? No, the best you could do is disable all shell access, or limit the commands that can be run via the shell, but the latter option is getting beyond the scope of a PHP question. Certainly, as is my normal custom, I could try it and find out for myself -- but I have always been reluctant to use shell commands. Besides, never having used them, I don't see their advantage yet. Currently, they seem strange and dangerous to me. If you're doing it on php1.net, you're safe. The only damage that can happen on that server is to your own account. That's unfortunately not true of all hosting providers, but you're good there. ;-P -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Friday Distraction
On Oct 28, 2011, at 9:43 AM, Stuart Dallas wrote On 28 Oct 2011, at 12:54, Daniel Brown wrote: On Fri, Oct 28, 2011 at 05:03, Adam Richardson simples...@gmail.com wrote: Well, Daniel, I'll bet you never thought that your Friday Distraction would elicit such a broad range of responses AND keep the commentary coming right through to the next Friday. Nice :) This is nothing compared to how it used to be ~2007-08. ;-P Ahh, the good old days! To all: To me -- these ARE the good old days. Even though the economy is in the dumpster, quantity of business is down, and clients are harder to please, this time has presented me with more enjoyable challenges than ~2007-8. Of course, this could be just me trying to keep current with technology while not realizing I am falling behind. But, it feels like things are better now -- sometimes ignorance is bliss. Strive to be happy. Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execute permission question
On Oct 28, 2011, at 11:07 AM, Daniel Brown wrote: On Fri, Oct 28, 2011 at 11:01, Tedd Sperling tedd.sperl...@gmail.com wrote: But does having execute permissions set on a script affect the scripts ability to run shell commands? Negative. It won't inherit permissions, though one might expect that to make sense. For example, if I have a script that contains a shell command, can I prohibit that script from executing the command by setting it's execute permission to not execute? No, the best you could do is disable all shell access, or limit the commands that can be run via the shell, but the latter option is getting beyond the scope of a PHP question. Certainly, as is my normal custom, I could try it and find out for myself -- but I have always been reluctant to use shell commands. Besides, never having used them, I don't see their advantage yet. Currently, they seem strange and dangerous to me. If you're doing it on php1.net, you're safe. The only damage that can happen on that server is to your own account. That's unfortunately not true of all hosting providers, but you're good there. ;-P -- /Daniel P. Brown Mucho thanks for the clarification, information, and authorization. I'll keep that in mind re php1.net and try not to be a teddzilla when I investigate shell commands. :-) Cheers, tedd PS: I have not trimmed the post because I think it is important to repeat this. t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] Execute permission question
On 28 Oct 2011 at 16:01, Tedd Sperling tedd.sperl...@gmail.com wrote: On Oct 27, 2011, at 7:49 PM, Daniel Brown wrote: But does having execute permissions set on a script affect the scripts ability to run shell commands? No, as Dan has said. But if you have a file called wiggy, containing the following: #!/usr/bin/php ?php echo Hello World!\n; ? then you can run it at the command line by typing its name at the prompt - but wiggy will need to have execute permission set. -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Friday Distraction
On Fri, Oct 28, 2011 at 11:16 AM, Tedd Sperling tedd.sperl...@gmail.com wrote: On Oct 28, 2011, at 9:43 AM, Stuart Dallas wrote On 28 Oct 2011, at 12:54, Daniel Brown wrote: On Fri, Oct 28, 2011 at 05:03, Adam Richardson simples...@gmail.com wrote: Well, Daniel, I'll bet you never thought that your Friday Distraction would elicit such a broad range of responses AND keep the commentary coming right through to the next Friday. Nice :) This is nothing compared to how it used to be ~2007-08. ;-P Ahh, the good old days! To all: To me -- these ARE the good old days. Even though the economy is in the dumpster, quantity of business is down, and clients are harder to please, this time has presented me with more enjoyable challenges than ~2007-8. Of course, this could be just me trying to keep current with technology while not realizing I am falling behind. But, it feels like things are better now -- sometimes ignorance is bliss. Strive to be happy. Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Mr Brown, You're not going to try and pawn this thread off as the Friday Distraction, are you? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Friday Distraction
On Fri, Oct 28, 2011 at 11:51, Eric Butera eric.but...@gmail.com wrote: Mr Brown, You're not going to try and pawn this thread off as the Friday Distraction, are you? No, I'm waiting for someone else to set themselves on fire in front of the crowd of onlookers this week. My email this week would otherwise have been nothing but a picture of a hydraulic jack, useful for lifting the respective rocks from those who have been living beneath them. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Friday Distraction
On Fri, Oct 28, 2011 at 12:02 PM, Daniel Brown danbr...@php.net wrote: On Fri, Oct 28, 2011 at 11:51, Eric Butera eric.but...@gmail.com wrote: Mr Brown, You're not going to try and pawn this thread off as the Friday Distraction, are you? No, I'm waiting for someone else to set themselves on fire in front of the crowd of onlookers this week. My email this week would otherwise have been nothing but a picture of a hydraulic jack, useful for lifting the respective rocks from those who have been living beneath them. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ That doesn't sound controversial enough. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Why does this script run out of memory?
I'm running PHP 5.3.8 on FreeBSD 8.2 with MySQL 5.1.55. The script below is designed to be able to WHILE it's way through a MySQL query result set, and process each row. However, it runs out of memory a little after a quarter million rows. The schema fields total to about 200 bytes per row, so the row size doesn't seem very large. Why is this running out of memory? Thank you! Jim ?php $test_db_host = localhost; $test_db_user = foo; $test_db_pwd = bar; $test_db_name = farkle; $db_host = $test_db_host; $db_user = $test_db_user; $db_name = $test_db_name; $db_pwd = $test_db_pwd; if (!($db_conn = mysql_connect( $db_host, $db_user, $db_pwd ))) die( Can't connect to MySQL server\n ); if (!mysql_select_db( $db_name, $db_conn )) die( Can't connect to database $db_name\n ); $qry = select * from test_table order by contract; if ($result = mysql_query( $qry, $db_conn )) { $n = 0; while ($row = mysql_fetch_assoc( $result )) { // process row here $n++; } // while mysql_free_result($result); echo $n\n; } else { die( mysql_error() . \n ); } ? PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes) in xx3.php on line 24 Line 24 is: 24 while ($row = mysql_fetch_assoc( $result )) { -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Object size
Is there a function or method that calculate the object size in PHP?. Or maybe that calculates a xml buffer of a file? I need to check a size of a file, and if it's size is bigger than 500kb. I will need to make another file to the subsequent content. Any help will serve. Tks, Volmar -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 12:38 PM, Jim Long p...@umpquanet.com wrote: I'm running PHP 5.3.8 on FreeBSD 8.2 with MySQL 5.1.55. The script below is designed to be able to WHILE it's way through a MySQL query result set, and process each row. However, it runs out of memory a little after a quarter million rows. The schema fields total to about 200 bytes per row, so the row size doesn't seem very large. Why is this running out of memory? Thank you! Jim ?php $test_db_host = localhost; $test_db_user = foo; $test_db_pwd = bar; $test_db_name = farkle; $db_host = $test_db_host; $db_user = $test_db_user; $db_name = $test_db_name; $db_pwd = $test_db_pwd; if (!($db_conn = mysql_connect( $db_host, $db_user, $db_pwd ))) die( Can't connect to MySQL server\n ); if (!mysql_select_db( $db_name, $db_conn )) die( Can't connect to database $db_name\n ); $qry = select * from test_table order by contract; if ($result = mysql_query( $qry, $db_conn )) { $n = 0; while ($row = mysql_fetch_assoc( $result )) { // process row here $n++; } // while mysql_free_result($result); echo $n\n; } else { die( mysql_error() . \n ); } ? PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes) in xx3.php on line 24 Line 24 is: 24 while ($row = mysql_fetch_assoc( $result )) { -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Not sure what is happening inside process row here, but I'm sure that is where your issue is. Instead of building some giant structure inside of that while statement you should flush it out to the screen. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 01:21:36PM -0400, Eric Butera wrote: On Fri, Oct 28, 2011 at 12:38 PM, Jim Long p...@umpquanet.com wrote: I'm running PHP 5.3.8 on FreeBSD 8.2 with MySQL 5.1.55. The script below is designed to be able to WHILE it's way through a MySQL query result set, and process each row. However, it runs out of memory a little after a quarter million rows. ??The schema fields total to about 200 bytes per row, so the row size doesn't seem very large. Why is this running out of memory? Thank you! Jim ?php $test_db_host = localhost; $test_db_user = foo; $test_db_pwd ??= bar; $test_db_name = farkle; $db_host = $test_db_host; $db_user = $test_db_user; $db_name = $test_db_name; $db_pwd ??= $test_db_pwd; if (!($db_conn = mysql_connect( $db_host, $db_user, $db_pwd ))) ?? ?? ?? ??die( Can't connect to MySQL server\n ); if (!mysql_select_db( $db_name, $db_conn )) ?? ?? ?? ??die( Can't connect to database $db_name\n ); $qry = select * from test_table order by contract; if ($result = mysql_query( $qry, $db_conn )) { ?? ?? ?? ??$n = 0; ?? ?? ?? ??while ($row = mysql_fetch_assoc( $result )) { // process row here ?? ?? ?? ?? ?? ?? ?? ??$n++; ?? ?? ?? ??} // while ?? ?? ?? ??mysql_free_result($result); ?? ?? ?? ??echo $n\n; } else { ?? ?? ?? ??die( mysql_error() . \n ); } ? PHP Fatal error: ??Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes) in xx3.php on line 24 Line 24 is: ?? ??24 ?? ?? ?? ?? ??while ($row = mysql_fetch_assoc( $result )) { -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Not sure what is happening inside process row here, but I'm sure that is where your issue is. Instead of building some giant structure inside of that while statement you should flush it out to the screen. Eric: Thanks for your reply. process row here is a comment. It doesn't do anything. The script, exactly as shown, runs out of memory, exactly as shown. Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] Why does this script run out of memory?
Original Message From: Eric Butera eric.but...@gmail.com To: Jim Long p...@umpquanet.com Cc: php-general@lists.php.net Sent: Fri, Oct 28, 2011, 1:22 PM Subject: Re: [PHP] Why does this script run out of memory? On Fri, Oct 28, 2011 at 12:38 PM, Jim Long p...@umpquanet.com wrote: I'm running PHP 5.3.8 on FreeBSD 8.2 with MySQL 5.1.55. The script below is designed to be able to WHILE it's way through a MySQL query result set, and process each row. However, it runs out of memory a little after a quarter million rows. The schema fields total to about 200 bytes per row, so the row size doesn't seem very large. Why is this running out of memory? Thank you! Jim ?php $test_db_host = localhost; $test_db_user = foo; $test_db_pwd = bar; $test_db_name = farkle; $db_host = $test_db_host; $db_user = $test_db_user; $db_name = $test_db_name; $db_pwd = $test_db_pwd; if (!($db_conn = mysql_connect( $db_host, $db_user, $db_pwd ))) die( Can't connect to MySQL server\n ); if (!mysql_select_db( $db_name, $db_conn )) die( Can't connect to database $db_name\n ); $qry = select * from test_table order by contract; if ($result = mysql_query( $qry, $db_conn )) { $n = 0; while ($row = mysql_fetch_assoc( $result )) { // process row here $n++; } // while mysql_free_result($result); echo $n\n; } else { die( mysql_error() . \n ); } ? PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes) in xx3.php on line 24 Line 24 is: 24 while ($row = mysql_fetch_assoc( $result )) { -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Not sure what is happening inside process row here, but I'm sure that is where your issue is. Instead of building some giant structure inside of that while statement you should flush it out to the screen. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Try unsetting the $row variable, you may be fetching extremely large rows but that's a big if, because your script is allowed to allocate 128MB of memory before puking. Are you dealing with very large data sets from the database? If you are dealing with large data sets, then try redefining your query. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] Why does this script run out of memory?
On Fri, 2011-10-28 at 13:32 -0400, James wrote: Original Message From: Eric Butera eric.but...@gmail.com To: Jim Long p...@umpquanet.com Cc: php-general@lists.php.net Sent: Fri, Oct 28, 2011, 1:22 PM Subject: Re: [PHP] Why does this script run out of memory? On Fri, Oct 28, 2011 at 12:38 PM, Jim Long p...@umpquanet.com wrote: I'm running PHP 5.3.8 on FreeBSD 8.2 with MySQL 5.1.55. The script below is designed to be able to WHILE it's way through a MySQL query result set, and process each row. However, it runs out of memory a little after a quarter million rows. The schema fields total to about 200 bytes per row, so the row size doesn't seem very large. Why is this running out of memory? Thank you! Jim ?php $test_db_host = localhost; $test_db_user = foo; $test_db_pwd = bar; $test_db_name = farkle; $db_host = $test_db_host; $db_user = $test_db_user; $db_name = $test_db_name; $db_pwd = $test_db_pwd; if (!($db_conn = mysql_connect( $db_host, $db_user, $db_pwd ))) die( Can't connect to MySQL server\n ); if (!mysql_select_db( $db_name, $db_conn )) die( Can't connect to database $db_name\n ); $qry = select * from test_table order by contract; if ($result = mysql_query( $qry, $db_conn )) { $n = 0; while ($row = mysql_fetch_assoc( $result )) { // process row here $n++; } // while mysql_free_result($result); echo $n\n; } else { die( mysql_error() . \n ); } ? PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes) in xx3.php on line 24 Line 24 is: 24 while ($row = mysql_fetch_assoc( $result )) { -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Not sure what is happening inside process row here, but I'm sure that is where your issue is. Instead of building some giant structure inside of that while statement you should flush it out to the screen. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Try unsetting the $row variable, you may be fetching extremely large rows but that's a big if, because your script is allowed to allocate 128MB of memory before puking. Are you dealing with very large data sets from the database? If you are dealing with large data sets, then try redefining your query. I don't think that will help, as it gets reset each time it iterates the loop when it's given a new value. Have you tried narrowing down your query to only the fields that you need in your script? Instead of SELECT * FROM test_table try something like SELECT field1, field2, etc FROM test_table Another thing to try is running this in over the command line if you can. I've had a lot of success with memory intensive scripts like this. Although it may not help in your specific case, it's worth noting at least. -- Thanks, Ash http://www.ashleysheridan.co.uk
Re: Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 01:32:32PM -0400, James wrote: On Fri, Oct 28, 2011 at 12:38 PM, Jim Long p...@umpquanet.com wrote: I'm running PHP 5.3.8 on FreeBSD 8.2 with MySQL 5.1.55. The script below is designed to be able to WHILE it's way through a MySQL query result set, and process each row. However, it runs out of memory a little after a quarter million rows. ??The schema fields total to about 200 bytes per row, so the row size doesn't seem very large. Why is this running out of memory? Thank you! Jim ?php $test_db_host = localhost; $test_db_user = foo; $test_db_pwd ??= bar; $test_db_name = farkle; $db_host = $test_db_host; $db_user = $test_db_user; $db_name = $test_db_name; $db_pwd ??= $test_db_pwd; if (!($db_conn = mysql_connect( $db_host, $db_user, $db_pwd ))) ?? ?? ?? ??die( Can't connect to MySQL server\n ); if (!mysql_select_db( $db_name, $db_conn )) ?? ?? ?? ??die( Can't connect to database $db_name\n ); $qry = select * from test_table order by contract; if ($result = mysql_query( $qry, $db_conn )) { ?? ?? ?? ??$n = 0; ?? ?? ?? ??while ($row = mysql_fetch_assoc( $result )) { // process row here ?? ?? ?? ?? ?? ?? ?? ??$n++; ?? ?? ?? ??} // while ?? ?? ?? ??mysql_free_result($result); ?? ?? ?? ??echo $n\n; } else { ?? ?? ?? ??die( mysql_error() . \n ); } ? PHP Fatal error: ??Allowed memory size of 134217728 bytes exhausted (tried to allocate 20 bytes) in xx3.php on line 24 Line 24 is: ?? ??24 ?? ?? ?? ?? ??while ($row = mysql_fetch_assoc( $result )) { Not sure what is happening inside process row here, but I'm sure that is where your issue is. Instead of building some giant structure inside of that while statement you should flush it out to the screen. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Try unsetting the $row variable, you may be fetching extremely large rows but that's a big if, because your script is allowed to allocate 128MB of memory before puking. Are you dealing with very large data sets from the database? If you are dealing with large data sets, then try redefining your query. James: Thanks for taking time to help. The row size is small by my standards (see below). The query result has just under 300,000 records, and it's puking about 90% of the way through. Changing the while loop to: while ($row = mysql_fetch_assoc( $result )) { $n++; echo sprintf( %7d %12d\n, $n, memory_get_peak_usage() ); } // while the tail end of the output becomes: 274695134203084 274696134203524 274697134203964 PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 240 bytes) in xx3.php on line 26 Changing the while loop further to: while ($row = mysql_fetch_assoc( $result )) { unset( $row ); $n++; echo sprintf( %7d %12d\n, $n, memory_get_peak_usage() ); } // while the tail end of the output becomes: 274695134202232 274696134202672 274697134203112 274698134203552 274699134203992 PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 240 bytes) in xx3.php on line 27 So it does get a little farther through the dataset, but not much. Jim mysql describe test_table; +--+-+--+-+-+---+ | Field| Type| Null | Key | Default | Extra | +--+-+--+-+-+---+ | contract | int(11) | YES | | NULL| | | A| int(8) unsigned | NO | | 0 | | | B| datetime| YES | | NULL| | | C| int(8) unsigned | YES | | 0 | | | D| char(8) | YES | | NULL| | | E| char(8) | YES | | | | | F| int(4) | YES | | 0 | | | G| int(1) | YES | | 0 | | | H| char(8) | YES | | 00:00 | | | I| varchar(100)| YES | | XXX | | +--+-+--+-+-+---+ 10 rows in set (0.00 sec) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] BP for Looping through an Array
Hi all. Am wondering if there is a best practice for looping through an array, when you need both the item and its position (ie. 1, 2, 3). The two ways I know of: // the for loop tracks the position and you get each item from the array $allFiles = array(coffee.jpg, tea.jpg, milk.jpg); $numberOfFiles = count($allFiles); for ($i=1; $i=$numberOfFiles; $i++) { $currFile = $allFiles[$i - 1]; // since arrays start with 0 doThisWith($currFile); doThatWith($i); } OR: // the for loop gets each item and you track the position $allFiles = array(coffee.jpg, tea.jpg, milk.jpg); $counter = 1; foreach ($allFiles as $currFile) { doThisWith($currFile); doThatWith($counter); $counter += 1; } Both are the same number of lines, but my tests (see code below) indicate that the foreach loop is twice as fast. Anyone have a better way - faster, more efficient, cooler, etc.? (Or see some flaw in my test code below?) Thanks. George Langley -- TEST CODE -- ?php echo h1Loop Test/h1; // create a large array $theArray = array(); for ($i=1; $i=100; $i++) { array_push($theArray, $i); } $confirmCount = count($theArray); echo h2An array of $confirmCount items (numbers 1 to $confirmCount) has been created./h2; echo tabletrtdbType of Loop/b/tdtdbTime Taken to Add Up/b/tdtdbaddUp Value/b/td/tr; for ($x=1; $x=10; $x++) { // run tests 10x // the for loop tracks the position and you get each item from the array $addUp = 0; $time_start = microtime(true); $numberOfItems = count($theArray); for ($i=1; $i=$numberOfItems; $i++) { $currItem = $theArray[$i - 1]; // since arrays start with 0 $addUp += $currItem; // give it something to do } $time_end = microtime(true); $time = $time_end - $time_start; echo trtdFor (Tracks Position): /tdtd$time/tdtd$addUp/td/tr; // the for loop gets each item and you track the position $addUp = 0; $time_start = microtime(true); $counter = 1; foreach ($theArray as $currItem) { $addUp += $currItem; // give it something to do $counter += 1; } $time_end = microtime(true); $time = $time_end - $time_start; echo trtdForeach (Tracks Items): /tdtd$time/tdtd$addUp/td/tr; echo trtdnbsp;/tdtdnbsp;/tdtdnbsp;/td/tr; } echo /table; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] BP for Looping through an Array
On Fri, Oct 28, 2011 at 12:09:24PM -0600, George Langley wrote: Hi all. Am wondering if there is a best practice for looping through an array, when you need both the item and its position (ie. 1, 2, 3). The two ways I know of: // the for loop tracks the position and you get each item from the array $allFiles = array(coffee.jpg, tea.jpg, milk.jpg); $numberOfFiles = count($allFiles); for ($i=1; $i=$numberOfFiles; $i++) { $currFile = $allFiles[$i - 1]; // since arrays start with 0 doThisWith($currFile); doThatWith($i); } OR: // the for loop gets each item and you track the position $allFiles = array(coffee.jpg, tea.jpg, milk.jpg); $counter = 1; foreach ($allFiles as $currFile) { doThisWith($currFile); doThatWith($counter); $counter += 1; } Both are the same number of lines, but my tests (see code below) indicate that the foreach loop is twice as fast. Anyone have a better way - faster, more efficient, cooler, etc.? (Or see some flaw in my test code below?) Thanks. George Langley If you are certain that your array is consecutively indexed from 0, you can shave two lines off your code with: $allFiles = array(coffee.jpg, tea.jpg, milk.jpg); foreach ($allFiles as $key = $currFile) { doThisWith($currFile); doThatWith($key+1); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why does this script run out of memory?
If all you want to do is count the records, why are you not letting sql do it for you instead of doing the while loop? That's all that script is doing, if that is the exact code you ran. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 14:05, Jim Long p...@umpquanet.com wrote: the tail end of the output becomes: 274695 134202232 274696 134202672 274697 134203112 274698 134203552 274699 134203992 PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 240 bytes) in xx3.php on line 27 Each row increases memory allocation by 440 bytes. 274,700 rows would equal 120,868,000 bytes of MySQL data in the buffer. Subtracting the 240 bytes from the 440 anticipated in the 274,700th row, that means the memory footprint of your script in execution (including PHP and its extensions, Apache, the MySQL connection, et cetera) is utilizing 13,349,928 (roughly 13.4MB), which is pretty average, depending on the configuration and bloat of the builds you're using. Ways around this: increase memory allocation and risk bogging-down your machine, or use mysql_unbuffered_query(). -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 13:25, Jim Long p...@umpquanet.com wrote: Eric: Thanks for your reply. process row here is a comment. It doesn't do anything. The script, exactly as shown, runs out of memory, exactly as shown. My response presumes that you're planning on placing something into this comment area, in which the memory will only further increase. If *presumed* should be replaced by *ASSumed* in this case, skip mysql_unbuffered_query() and go straight for mysql_num_rows(). Do not pass GO. Do not collect $200. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] BP for Looping through an Array
On Fri, Oct 28, 2011 at 14:18, Jim Long p...@umpquanet.com wrote: If you are certain that your array is consecutively indexed from 0, you can shave two lines off your code with: $allFiles = array(coffee.jpg, tea.jpg, milk.jpg); foreach ($allFiles as $key = $currFile) { doThisWith($currFile); doThatWith($key+1); } See also: http://php.net/array_walk -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 03:24:37PM -0400, Jim Giner wrote: If all you want to do is count the records, why are you not letting sql do it for you instead of doing the while loop? That's all that script is doing, if that is the exact code you ran. Hi, Jim. Thank you for replying. One of the key concepts of troubleshooting is that when you encounter a problem, you try to state the problem with as simple a test case as possible, so that testing will not be complicated by extraneous variables or code that may or may not have any impact on the problem. I don't want to just count the records, I want to get some work done for a client. That work involves processing every record in the result set. Counting is just a simple process to conduct for the purpose of debugging this loop algorithm. The problem is that this algorithm fails to process all the records in the result set. I appreciate any insights you have as to why that is happening. Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 3:29 PM, Daniel Brown danbr...@php.net wrote: On Fri, Oct 28, 2011 at 13:25, Jim Long p...@umpquanet.com wrote: Eric: Thanks for your reply. process row here is a comment. It doesn't do anything. The script, exactly as shown, runs out of memory, exactly as shown. My response presumes that you're planning on placing something into this comment area, in which the memory will only further increase. If *presumed* should be replaced by *ASSumed* in this case, skip mysql_unbuffered_query() and go straight for mysql_num_rows(). Do not pass GO. Do not collect $200. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ I was glad to learn what comments were. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 16:21, Jim Long p...@umpquanet.com wrote: I will try experimenting with Daniel's idea of unbuffered queries, but my understanding is that while an unbuffered result resource is in use, no other SQL transactions can be conducted. Maybe I can get around that by using one MySQL connection for the unbuffered query, and another separate MySQL connection for the incidental SQL queries that I need to perform as I process each record from the large dataset. Just for the sake of a kick-start, you could throw together a simple class and then call that quite easily. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 03:42:48PM -0400, Eric Butera wrote: On Fri, Oct 28, 2011 at 3:29 PM, Daniel Brown danbr...@php.net wrote: On Fri, Oct 28, 2011 at 13:25, Jim Long p...@umpquanet.com wrote: Eric: Thanks for your reply. process row here is a comment. ??It doesn't do anything. ??The script, exactly as shown, runs out of memory, exactly as shown. ?? ??My response presumes that you're planning on placing something into this comment area, in which the memory will only further increase. ??If *presumed* should be replaced by *ASSumed* in this case, skip mysql_unbuffered_query() and go straight for mysql_num_rows(). Do not pass GO. ??Do not collect $200. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ I was glad to learn what comments were. Eric: Please forgive me if I was curt in my message to you. I don't mean to bite the hands that are trying to help. As Daniel rightly observed, my concern is just that if a pretty much empty while loop runs out of memory when trying to step through each record, I'm really going to be hosed if I try to start doing some productive work within the while loop. Daniel's memory trend analysis is helpful. I'm testing from the command line, so there's no Apache overhead, but the memory usage starts as: 1 12145496 2 12145976 3 12146408 4 12146804 5 12147200 6 12147596 ... I normally prefer to work in PostgreSQL, but the client has already gone down the MySQL road. Just for edification's sake, I exported the table in PostgreSQL and re-worked my code: if (!($db_conn = pg_connect( host=$db_host user=$db_user dbname=$db_name password=$db_pwd ))) die( Can't connect to SQL server\n ); $qry = select * from test_table order by contract; if ($result = pg_query( $db_conn, $qry )) { $n = 0; while ($row = pg_fetch_assoc( $result )) { unset( $row ); $n++; echo sprintf( %7d %12d\n, $n, memory_get_peak_usage() ); } // while pg_free_result($result); echo $n\n; } else { die( pg_last_error() . \n ); } Using PostgreSQL (on a completely different machine), this runs to completion, and memory consumption is nearly flat: 1 329412 2 329724 3 329796 4 329796 5 329796 ... 295283 329860 295284 329860 295285 329860 295286 329860 295287 329860 295287 If one were to describe the memory consumption as a 'leak', then PostgreSQL is leaking at a much slower rate than MySQL. Postgres leaks as much over the entire run (329860-329412=448) as MySQL does on each row. Put another way, the MySQL version leaks memory almost 300,000 times faster. My PostgreSQL machine also has MySQL installed, so I ran the MySQL version of the code on that machine for testing, a second opinion if you like. It leaked memory almost as bad as my client's PHP/MySQL installation, but a little more slowly, 396 bytes or so per row. The slower memory consumption enabled the code to run to completion, barely: 1 12149492 2 12149972 3 12150404 4 12150800 ... 295284129087704 295285129088100 295286129088496 295287129088892 295287 So is this just a difference in the programming quality of the database extensions for MySQL vs. PostgreSQL that one gobbles up memory profusely, while the other one has only a slight, slow leak? I will try experimenting with Daniel's idea of unbuffered queries, but my understanding is that while an unbuffered result resource is in use, no other SQL transactions can be conducted. Maybe I can get around that by using one MySQL connection for the unbuffered query, and another separate MySQL connection for the incidental SQL queries that I need to perform as I process each record from the large dataset. Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 9:38 AM, Jim Long p...@umpquanet.com wrote: I'm running PHP 5.3.8 on FreeBSD 8.2 with MySQL 5.1.55. Jim, Installed from packages or standard port tree build? Did you do any tweak for the ports build? Any special compiler parameters in your make.conf? I've noticed that you used MySQL extensions. Have you tried MySQLi to see if there's any difference? Regards, Tommy
Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 1:38 PM, Jim Long p...@umpquanet.com wrote: I'm running PHP 5.3.8 on FreeBSD 8.2 with MySQL 5.1.55. The script below is designed to be able to WHILE it's way through a MySQL query result set, and process each row. However, it runs out of memory a little after a quarter million rows. The schema fields total to about 200 bytes per row, so the row size doesn't seem very large. Why is this running out of memory? Thank you! Jim ?php $test_db_host = localhost; $test_db_user = foo; $test_db_pwd = bar; $test_db_name = farkle; $db_host = $test_db_host; $db_user = $test_db_user; $db_name = $test_db_name; $db_pwd = $test_db_pwd; if (!($db_conn = mysql_connect( $db_host, $db_user, $db_pwd ))) die( Can't connect to MySQL server\n ); if (!mysql_select_db( $db_name, $db_conn )) die( Can't connect to database $db_name\n ); $qry = select * from test_table order by contract; if ($result = mysql_query( $qry, $db_conn )) { $n = 0; while ($row = mysql_fetch_assoc( $result )) { // process row here $n++; } // while Whats the difference between fetch_assoc and fetch_row? I use: while ($row = mysql_fetch_row($theQuery)) { doCartwheel; } on just under 300 million rows and nothing craps out. I have memory_limit set to 4GB though. Although, IIRC I pushed it up for GD not mysql issues. Same OS and php ver, MySQL is 5.1.48 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Object size
On Fri, Oct 28, 2011 at 9:43 AM, QI.VOLMAR QI qi.vol...@gmail.com wrote: Is there a function or method that calculate the object size in PHP?. Or maybe that calculates a xml buffer of a file? I need to check a size of a file, and if it's size is bigger than 500kb. I will need to make another file to the subsequent content. Any help will serve. Tks, Volmar http://php.net/ref.filesystem http://php.net/function.filesize
[PHP] mysql_fetch_array() vs mysql_fetch_assoc() WAS: Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 18:13, Paul Halliday paul.halli...@gmail.com wrote: Whats the difference between fetch_assoc and fetch_row? I use: while ($row = mysql_fetch_row($theQuery)) { doCartwheel; } on just under 300 million rows and nothing craps out. I have memory_limit set to 4GB though. Although, IIRC I pushed it up for GD not mysql issues. Same OS and php ver, MySQL is 5.1.48 Please don't hijack other's threads to ask a question. I've started this as a new thread to address this question. mysql_fetch_array() grabs all of the data and places it in a simple numerically-keyed array. By contrast, mysql_fetch_assoc() grabs it and populates an associative array. This means that the column names (or aliases, et cetera) become the keys for the array. With mysql_fetch_assoc(), you can still call an array key by number, but it's not vice-versa with mysql_fetch_array(). The difference in overhead, if you meant that (in which case, my apologies for reading it as a question of functional difference), is variable: it's based mainly on the difference between the bytes representing the integers used as keys in mysql_fetch_array() versus the size in bytes of the strings used as keys in mysql_fetch_assoc(). -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 02:57:02PM -0700, Tommy Pham wrote: On Fri, Oct 28, 2011 at 9:38 AM, Jim Long p...@umpquanet.com wrote: I'm running PHP 5.3.8 on FreeBSD 8.2 with MySQL 5.1.55. Jim, Installed from packages or standard port tree build? Did you do any tweak for the ports build? Any special compiler parameters in your make.conf? I've noticed that you used MySQL extensions. Have you tried MySQLi to see if there's any difference? Regards, Tommy MySQL server and PHP and extensions built from ports, without any local tweaks. Nothing very interesting in /etc/make.conf: MASTER_SITE_FREEBSD=1 CPUTYPE?=p3 USA_RESIDENT=YES NO_INET6=YES WITHOUT_IPV6=YES NO_I4B=true NO_BLUETOOTH=true NO_IPFILTER=true NO_KERBEROS=true NO_ATM=true # do not build ATM related programs and libraries NOUUCP=true # do not build uucp related programs NO_UUCP=true # do not build uucp related programs NO_GAMES=true NO_PROFILE=true PERL_VERSION=5.10.1 Port options for php5-extensions are: _OPTIONS_READ=php5-extensions-1.5 WITH_BCMATH=true WITHOUT_BZ2=true WITHOUT_CALENDAR=true WITH_CTYPE=true WITHOUT_CURL=true WITHOUT_DBA=true WITH_DOM=true WITHOUT_EXIF=true WITH_FILEINFO=true WITH_FILTER=true WITHOUT_FRIBIDI=true WITH_FTP=true WITHOUT_GD=true WITHOUT_GETTEXT=true WITHOUT_GMP=true WITH_HASH=true WITHOUT_ICONV=true WITHOUT_IMAP=true WITHOUT_INTERBASE=true WITH_JSON=true WITHOUT_LDAP=true WITHOUT_MBSTRING=true WITHOUT_MCRYPT=true WITHOUT_MSSQL=true WITH_MYSQL=true WITHOUT_MYSQLI=true WITHOUT_ODBC=true WITHOUT_OPENSSL=true WITHOUT_PCNTL=true WITH_PDF=true WITH_PDO=true WITHOUT_PDO_SQLITE=true WITH_PGSQL=true WITH_POSIX=true WITHOUT_PSPELL=true WITHOUT_READLINE=true WITHOUT_RECODE=true WITH_SESSION=true WITHOUT_SHMOP=true WITH_SIMPLEXML=true WITHOUT_SNMP=true WITHOUT_SOAP=true WITHOUT_SOCKETS=true WITHOUT_SQLITE=true WITHOUT_SQLITE3=true WITHOUT_SYBASE_CT=true WITHOUT_SYSVMSG=true WITHOUT_SYSVSEM=true WITHOUT_SYSVSHM=true WITHOUT_TIDY=true WITH_TOKENIZER=true WITHOUT_WDDX=true WITH_XML=true WITH_XMLREADER=true WITHOUT_XMLRPC=true WITH_XMLWRITER=true WITHOUT_XSL=true WITHOUT_YAZ=true WITHOUT_ZIP=true WITHOUT_ZLIB=true As Daniel suggested, using mysql_query_unbuffered works a treat, at the expense of a small amount of additional programming complexity. In my prior work with Postgres, I found that it would handle small or large datasets with equal ease, so I was surprised to find that MySQL blew up given a sufficient number of repeated calls to mysql_fetch_row(); Thank you for mentioning MySQLi. Although it is alphabetically adjacent in the documentation, it had never drawn my attention. I'll build the PHP extension and take a look when time permits. Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: mysql_fetch_array() vs mysql_fetch_assoc() WAS: Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 7:19 PM, Daniel Brown danbr...@php.net wrote: On Fri, Oct 28, 2011 at 18:13, Paul Halliday paul.halli...@gmail.com wrote: Whats the difference between fetch_assoc and fetch_row? I use: while ($row = mysql_fetch_row($theQuery)) { doCartwheel; } on just under 300 million rows and nothing craps out. I have memory_limit set to 4GB though. Although, IIRC I pushed it up for GD not mysql issues. Same OS and php ver, MySQL is 5.1.48 Please don't hijack other's threads to ask a question. I've started this as a new thread to address this question. mysql_fetch_array() grabs all of the data and places it in a simple numerically-keyed array. By contrast, mysql_fetch_assoc() grabs it and populates an associative array. This means that the column names (or aliases, et cetera) become the keys for the array. With mysql_fetch_assoc(), you can still call an array key by number, but it's not vice-versa with mysql_fetch_array(). The difference in overhead, if you meant that (in which case, my apologies for reading it as a question of functional difference), is variable: it's based mainly on the difference between the bytes representing the integers used as keys in mysql_fetch_array() versus the size in bytes of the strings used as keys in mysql_fetch_assoc(). -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ Sorry. I was just throwing it out there with the hope that there might be a tidbit that would help the OP. I have a simliar setup and I can query far more than a 1/4 million rows. What I offered is what I am doing differently. -- Paul Halliday http://www.squertproject.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Friday Distraction
Hi gang, Thinking database i/o would be the slowest part of a request in your new zf / amf app? Leave it to Zend_Amf to burn more cycles marshaling the protocol! http://s289.photobucket.com/albums/ll238/quickshiftin/?action=viewcurrent=ScreenShot2011-10-24at74724PM.png Happy Halloween! -nathan
Re: [PHP] mysql_fetch_array() vs mysql_fetch_assoc() WAS: Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 06:19:56PM -0400, Daniel Brown wrote: On Fri, Oct 28, 2011 at 18:13, Paul Halliday paul.halli...@gmail.com wrote: Whats the difference between fetch_assoc and fetch_row? I use: while ($row = mysql_fetch_row($theQuery)) { ? ?doCartwheel; } on just under 300 million rows and nothing craps out. I have memory_limit set to 4GB though. Although, IIRC I pushed it up for GD not mysql issues. Same OS and php ver, MySQL is 5.1.48 Please don't hijack other's threads to ask a question. I've started this as a new thread to address this question. mysql_fetch_array() grabs all of the data and places it in a simple numerically-keyed array. By contrast, mysql_fetch_assoc() grabs it and populates an associative array. This means that the column names (or aliases, et cetera) become the keys for the array. With mysql_fetch_assoc(), you can still call an array key by number, but it's not vice-versa with mysql_fetch_array(). I'm not seeing any numeric keys in my mysql_fetch_assoc() arrays. However, mysql_fetch_row (by default) does both: the array will be indexed numerically from 0 to N-1 corresponding to the table's N columns, and the array will also have string key indices which correspond to the query's column names. So by default, mysql_fetch_row uses twice the amount of data, because each field appears in the array twice. var_dump( $row ) will show in graphic detail. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_fetch_array() vs mysql_fetch_assoc() WAS: Re: [PHP] Why does this script run out of memory?
On Fri, Oct 28, 2011 at 18:48, Jim Long p...@umpquanet.com wrote: I'm not seeing any numeric keys in my mysql_fetch_assoc() arrays. You're absolutely correct, that's my mistake: substitute mysql_fetch_row() for mysql_fetch_assoc(). Duh. Time to call it a week -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Friday Distraction
On Fri, Oct 28, 2011 at 18:36, Nathan Nobbe quickshif...@gmail.com wrote: Hi gang, Thinking database i/o would be the slowest part of a request in your new zf / amf app? Leave it to Zend_Amf to burn more cycles marshaling the protocol! http://s289.photobucket.com/albums/ll238/quickshiftin/?action=viewcurrent=ScreenShot2011-10-24at74724PM.png Ends up looking startlingly like the original Sim City. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Friday Distraction
On Fri, Oct 28, 2011 at 7:07 PM, Daniel Brown danbr...@php.net wrote: On Fri, Oct 28, 2011 at 18:36, Nathan Nobbe quickshif...@gmail.com wrote: Hi gang, Thinking database i/o would be the slowest part of a request in your new zf / amf app? Leave it to Zend_Amf to burn more cycles marshaling the protocol! http://s289.photobucket.com/albums/ll238/quickshiftin/?action=viewcurrent=ScreenShot2011-10-24at74724PM.png Ends up looking startlingly like the original Sim City. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php kcachegrind is great. SimCity is great! Just the other day I was thinking about that soundtrack it played over the PC speaker, hilarious. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Friday Distraction
On Fri, Oct 28, 2011 at 5:23 PM, Eric Butera eric.but...@gmail.com wrote: On Fri, Oct 28, 2011 at 7:07 PM, Daniel Brown danbr...@php.net wrote: On Fri, Oct 28, 2011 at 18:36, Nathan Nobbe quickshif...@gmail.com wrote: Hi gang, Thinking database i/o would be the slowest part of a request in your new zf / amf app? Leave it to Zend_Amf to burn more cycles marshaling the protocol! http://s289.photobucket.com/albums/ll238/quickshiftin/?action=viewcurrent=ScreenShot2011-10-24at74724PM.png Ends up looking startlingly like the original Sim City. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php kcachegrind is great. SimCity is great! Just the other day I was thinking about that soundtrack it played over the PC speaker, hilarious. Agreed, the only thing that isn't great in this context .. Zend_Amf, haha! -nathan
Re: [PHP] Friday Distraction
On Fri, Oct 28, 2011 at 7:24 PM, Nathan Nobbe quickshif...@gmail.com wrote: On Fri, Oct 28, 2011 at 5:23 PM, Eric Butera eric.but...@gmail.com wrote: On Fri, Oct 28, 2011 at 7:07 PM, Daniel Brown danbr...@php.net wrote: On Fri, Oct 28, 2011 at 18:36, Nathan Nobbe quickshif...@gmail.com wrote: Hi gang, Thinking database i/o would be the slowest part of a request in your new zf / amf app? Leave it to Zend_Amf to burn more cycles marshaling the protocol! http://s289.photobucket.com/albums/ll238/quickshiftin/?action=viewcurrent=ScreenShot2011-10-24at74724PM.png Ends up looking startlingly like the original Sim City. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php kcachegrind is great. SimCity is great! Just the other day I was thinking about that soundtrack it played over the PC speaker, hilarious. Agreed, the only thing that isn't great in this context .. Zend_Amf, haha! -nathan I saw your post on that the other day - looks like there's a native php extension you might look into. The author was quite proud of the hasty response it was capable of, going as far as to say his library was faster than flash can decode it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Friday Distraction
On Fri, Oct 28, 2011 at 5:26 PM, Eric Butera eric.but...@gmail.com wrote: On Fri, Oct 28, 2011 at 7:24 PM, Nathan Nobbe quickshif...@gmail.com wrote: On Fri, Oct 28, 2011 at 5:23 PM, Eric Butera eric.but...@gmail.com wrote: On Fri, Oct 28, 2011 at 7:07 PM, Daniel Brown danbr...@php.net wrote: On Fri, Oct 28, 2011 at 18:36, Nathan Nobbe quickshif...@gmail.com wrote: Hi gang, Thinking database i/o would be the slowest part of a request in your new zf / amf app? Leave it to Zend_Amf to burn more cycles marshaling the protocol! http://s289.photobucket.com/albums/ll238/quickshiftin/?action=viewcurrent=ScreenShot2011-10-24at74724PM.png Ends up looking startlingly like the original Sim City. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php kcachegrind is great. SimCity is great! Just the other day I was thinking about that soundtrack it played over the PC speaker, hilarious. Agreed, the only thing that isn't great in this context .. Zend_Amf, haha! -nathan I saw your post on that the other day - looks like there's a native php extension you might look into. The author was quite proud of the hasty response it was capable of, going as far as to say his library was faster than flash can decode it. Yeah, I got it built under php 5.3, it rips. Funny thing is amfphp has a userpace serializer of it's own and it of course takes less time than db i/o. Dropping in the extension takes the time spent serializing down to practically nothing. Suffice it to say we'll be migrating to the extension on subsequent revision of the project I alluded to. Also, the more I use zf, the less I like, lol. Look at this line from the documentation - Fools! Zend_Server_Interface provides an interface that mimics PHP 5's SoapServer class; all server classes should implement this interface in order to provide a standard server API. -nathan
[PHP] Re:
.Do you want to feel orgasms several times? http://macrokid.ma.funpic.de/com.friend.page.php?jroyahoo_id=09ep0 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Why does this script run out of memory?
I had a spider written in PHP long ago. I had similar problems. because there were millions of rows of urls and I was fetching them in one single query. See inline, could this modification help you. Please test. On Fri, Oct 28, 2011 at 10:38 PM, Jim Long p...@umpquanet.com wrote: I'm running PHP 5.3.8 on FreeBSD 8.2 with MySQL 5.1.55. The script below is designed to be able to WHILE it's way through a MySQL query result set, and process each row. However, it runs out of memory a little after a quarter million rows. The schema fields total to about 200 bytes per row, so the row size doesn't seem very large. Why is this running out of memory? Thank you! Jim ?php $test_db_host = localhost; $test_db_user = foo; $test_db_pwd = bar; $test_db_name = farkle; $db_host = $test_db_host; $db_user = $test_db_user; $db_name = $test_db_name; $db_pwd = $test_db_pwd; if (!($db_conn = mysql_connect( $db_host, $db_user, $db_pwd ))) die( Can't connect to MySQL server\n ); if (!mysql_select_db( $db_name, $db_conn )) die( Can't connect to database $db_name\n ); $limit=10; $offset=0; while(1){ $qry = select * from test_table order by contract $offset, $limit; if ($result = mysql_query( $qry, $db_conn )) { $n = 0; while ($row = mysql_fetch_assoc( $result )) { // process row here $n++; } // while mysql_free_result($result); echo $n\n; } else { die( mysql_error() . \n ); // break the loop break; } $offset+=$limit; } ? Its the same thing but you are fetching data in chunks. Now this portion order by contract on quarter million rows is not a good practice. It will slow down your query time and make the script severely slow. I had about 100 millions of rows in my table in the url and I was sorting on last-visit column. Later I removed the order by and it was much faster. Try it and let us know. Thanks -- Shiplu Mokadd.im Follow me, http://twitter.com/shiplu Innovation distinguishes between follower and leader -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php