php-general Digest 9 Sep 2009 12:09:07 -0000 Issue 6330
php-general Digest 9 Sep 2009 12:09:07 - Issue 6330 Topics (messages 297798 through 297810): Re: Renaming a Directory 297798 by: Eddie Drapkin 297803 by: Paul M Foster 297805 by: Eddie Drapkin 297807 by: Ashley Sheridan 297810 by: Floyd Resler Re: Converting URL's to hyperlinks. 297799 by: Lupus Michaelis 297804 by: Paul M Foster Re: mysql user session handler 297800 by: Tom Worster 297801 by: Gabriel Sosa 297806 by: Ford, Mike Re: script failing at same line 297802 by: jim white XML. Prevent from turning into lt; 297808 by: Matthew Croud hi, how can i join a php document translate team? 297809 by: Hanjie Xu 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--- On Tue, Sep 8, 2009 at 5:39 PM, Floyd Reslerfres...@adex-intl.com wrote: How can I rename a directory with files in it? The rename function gives me a directory not empty error. I know I could do it be creating the directory, moving the files, and then deleting the old one. Is there an easier way? Thanks! Floyd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Is there something wrong with `system(mv $oldName $newName);` ? ---End Message--- ---BeginMessage--- On Tue, Sep 08, 2009 at 05:39:43PM -0400, Floyd Resler wrote: How can I rename a directory with files in it? The rename function gives me a directory not empty error. I know I could do it be creating the directory, moving the files, and then deleting the old one. Is there an easier way? It sounds like, underneath, rename() is creating a new directory and then attempting to delete the old one, ignoring the files in the original directory. In which case, you'll have to do it the long way-- create a new directory, move the files, then delete the old directory. Oddly enough, I can't find a *nix command which will actually rename a directory. The man pages for mv, rename and such all refer only to files, not directories. Paul -- Paul M. Foster ---End Message--- ---BeginMessage--- On Wed, Sep 9, 2009 at 12:08 AM, Paul M Fosterpa...@quillandmouse.com wrote: On Tue, Sep 08, 2009 at 05:39:43PM -0400, Floyd Resler wrote: How can I rename a directory with files in it? The rename function gives me a directory not empty error. I know I could do it be creating the directory, moving the files, and then deleting the old one. Is there an easier way? It sounds like, underneath, rename() is creating a new directory and then attempting to delete the old one, ignoring the files in the original directory. In which case, you'll have to do it the long way-- create a new directory, move the files, then delete the old directory. Oddly enough, I can't find a *nix command which will actually rename a directory. The man pages for mv, rename and such all refer only to files, not directories. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php mv renames directories fine: $ mkdir bar $ touch bar/randomfile $ mv bar foo $ ls foo randomfile :) ---End Message--- ---BeginMessage--- On Wed, 2009-09-09 at 00:08 -0400, Paul M Foster wrote: On Tue, Sep 08, 2009 at 05:39:43PM -0400, Floyd Resler wrote: How can I rename a directory with files in it? The rename function gives me a directory not empty error. I know I could do it be creating the directory, moving the files, and then deleting the old one. Is there an easier way? It sounds like, underneath, rename() is creating a new directory and then attempting to delete the old one, ignoring the files in the original directory. In which case, you'll have to do it the long way-- create a new directory, move the files, then delete the old directory. Oddly enough, I can't find a *nix command which will actually rename a directory. The man pages for mv, rename and such all refer only to files, not directories. Paul -- Paul M. Foster That's because in *nix, everything is a file. Directories, devices, all have file interfaces. Thanks, Ash http://www.ashleysheridan.co.uk ---End Message--- ---BeginMessage--- Nope, nothing wrong with that at all. Just didn't think of it! Thanks! Floyd On Sep 8, 2009, at 5:46 PM, Eddie Drapkin wrote: On Tue, Sep 8, 2009 at 5:39 PM, Floyd Reslerfres...@adex-intl.com wrote: How can I rename a directory with files in it? The rename function gives me a directory not empty error. I know I could do it be creating the directory, moving the files, and then deleting the old one. Is there an easier way? Thanks! Floyd --
RE: [PHP] mysql user session handler
-Original Message- From: Tom Worster [mailto:f...@thefsb.org] Sent: 09 September 2009 02:29 thanks, Devendra, that's pretty much the same as my handler. (though i can't figure Rich Smith's $sess_save_path global. do you know what is for?) I think if you look at the comments on that article, he's agreed that's an error and shouldn't be there. but what i'm really interested in is people's experience in switching over to and using this kind of handler: pitfalls, gotchas, etc. or is it really as easy and simple as all these online articles i've read about it claim? I moved from a single server to a load-balanced setup with 2 back-end servers. I switched to a database-based session handler very similar to the one under discussion (just tailored to my house style, really) and it just worked. Been running happily in production for about 6 months now. Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Renaming a Directory
On Wed, 2009-09-09 at 00:08 -0400, Paul M Foster wrote: On Tue, Sep 08, 2009 at 05:39:43PM -0400, Floyd Resler wrote: How can I rename a directory with files in it? The rename function gives me a directory not empty error. I know I could do it be creating the directory, moving the files, and then deleting the old one. Is there an easier way? It sounds like, underneath, rename() is creating a new directory and then attempting to delete the old one, ignoring the files in the original directory. In which case, you'll have to do it the long way-- create a new directory, move the files, then delete the old directory. Oddly enough, I can't find a *nix command which will actually rename a directory. The man pages for mv, rename and such all refer only to files, not directories. Paul -- Paul M. Foster That's because in *nix, everything is a file. Directories, devices, all have file interfaces. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] XML. Prevent from turning into lt;
Hiya, I'm writing an app that let's my client upload images, the image html code is added to an XML file. Take a look at the image element below: item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 /]]/image nameBlue Ski Trousers/name price8.99/price /item Now, whenever PHP writes this to the XML files, it turns the and into lt; and gt; . which means it does not display on the webpage. How can I prevent this from happening ? Many thanks, Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] hi, how can i join a php document translate team?
thank you
Re: [PHP] Renaming a Directory
Nope, nothing wrong with that at all. Just didn't think of it! Thanks! Floyd On Sep 8, 2009, at 5:46 PM, Eddie Drapkin wrote: On Tue, Sep 8, 2009 at 5:39 PM, Floyd Reslerfres...@adex-intl.com wrote: How can I rename a directory with files in it? The rename function gives me a directory not empty error. I know I could do it be creating the directory, moving the files, and then deleting the old one. Is there an easier way? Thanks! Floyd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Is there something wrong with `system(mv $oldName $newName);` ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML. Prevent from turning into lt;
On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croudm...@obviousdigital.com wrote: Hiya, I'm writing an app that let's my client upload images, the image html code is added to an XML file. Take a look at the image element below: item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 /]]/image nameBlue Ski Trousers/name price8.99/price /item Now, whenever PHP writes this to the XML files, it turns the and into lt; and gt; . which means it does not display on the webpage. How can I prevent this from happening ? Many thanks, Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php str_replace? -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Renaming a Directory
On Wed, Sep 09, 2009 at 12:11:14AM -0400, Eddie Drapkin wrote: On Wed, Sep 9, 2009 at 12:08 AM, Paul M Fosterpa...@quillandmouse.com wrote: On Tue, Sep 08, 2009 at 05:39:43PM -0400, Floyd Resler wrote: How can I rename a directory with files in it? The rename function gives me a directory not empty error. I know I could do it be creating the directory, moving the files, and then deleting the old one. Is there an easier way? It sounds like, underneath, rename() is creating a new directory and then attempting to delete the old one, ignoring the files in the original directory. In which case, you'll have to do it the long way-- create a new directory, move the files, then delete the old directory. Oddly enough, I can't find a *nix command which will actually rename a directory. The man pages for mv, rename and such all refer only to files, not directories. mv renames directories fine: $ mkdir bar $ touch bar/randomfile $ mv bar foo $ ls foo randomfile :) I would have thought so, but the man pages didn't mention it. I haven't use mv in ages. Makes sense that it would work, though. Moving/renaming a file would just change the name, not the inode number, which is the real key to *nix file systems. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql user session handler
On 9/9/09 4:16 AM, Ford, Mike m.f...@leedsmet.ac.uk wrote: -Original Message- From: Tom Worster [mailto:f...@thefsb.org] Sent: 09 September 2009 02:29 thanks, Devendra, that's pretty much the same as my handler. (though i can't figure Rich Smith's $sess_save_path global. do you know what is for?) I think if you look at the comments on that article, he's agreed that's an error and shouldn't be there. i didn't read any of the comments, thanks for pointing it out. while we're looking at mr. smith's article... Depending on how your code is structured, PHP does not always automatically save any session data. To be certain you are retaining your session data all the time, be sure to call the session_write_close() function at the end of each page. what are the specific conditions under which php _does_not_ write session data when a script terminate? according to the php manual, http://www.php.net/manual/en/function.session-write-close.php session_write_close() allows a script to release its lock on the session allowing other scripts to use it. it implies you wouldn't usually use it otherwise. but what i'm really interested in is people's experience in switching over to and using this kind of handler: pitfalls, gotchas, etc. or is it really as easy and simple as all these online articles i've read about it claim? I moved from a single server to a load-balanced setup with 2 back-end servers. I switched to a database-based session handler very similar to the one under discussion (just tailored to my house style, really) and it just worked. Been running happily in production for about 6 months now. thanks for the info. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] XML. Prevent from turning into lt;
From: Bastien Koert On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croudm...@obviousdigital.com wrote: Hiya, I'm writing an app that let's my client upload images, the image html code is added to an XML file. Take a look at the image element below: item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 /]]/image nameBlue Ski Trousers/name price8.99/price /item Now, whenever PHP writes this to the XML files, it turns the and into lt; and gt; . which means it does not display on the webpage. How can I prevent this from happening ? str_replace? Does the xml string get passed to htmlentities() or a similar function before it is sent to the browser? That would explain the substitutions. I saw an xmlentities() variation mentioned somewhere. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML. Prevent from turning into lt;
On 9 Sep 2009, at 14:26, Bastien Koert wrote: On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croudm...@obviousdigital.com wrote: Hiya, I'm writing an app that let's my client upload images, the image html code is added to an XML file. Take a look at the image element below: item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 /]]/image nameBlue Ski Trousers/name price8.99/price /item Now, whenever PHP writes this to the XML files, it turns the and into lt; and gt; . which means it does not display on the webpage. How can I prevent this from happening ? Many thanks, Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php str_replace? -- Bastien Cat, the other other white meat I've tried that but no matter what i do in the PHP side of things, as soon as I save that XML the conversion takes place. Should the XML be encoded in any way, is there a setting somewhere that prevents this ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML. Prevent from turning into lt;
On Wed, Sep 9, 2009 at 9:33 AM, Matthew Croud m...@obviousdigital.com wrote: On 9 Sep 2009, at 14:26, Bastien Koert wrote: On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croudm...@obviousdigital.com wrote: Hiya, I'm writing an app that let's my client upload images, the image html code is added to an XML file. Take a look at the image element below: item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 /]]/image nameBlue Ski Trousers/name price8.99/price /item Now, whenever PHP writes this to the XML files, it turns the and into lt; and gt; . which means it does not display on the webpage. How can I prevent this from happening ? Many thanks, Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php str_replace? -- Bastien Cat, the other other white meat I've tried that but no matter what i do in the PHP side of things, as soon as I save that XML the conversion takes place. Should the XML be encoded in any way, is there a setting somewhere that prevents this ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Perhaps you'd be so kind as to share with us what code you're using to generate the erroneous XML? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML. Prevent from turning into lt;
On 9 Sep 2009, at 14:36, Bob McConnell wrote: From: Bastien Koert On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croudm...@obviousdigital.com wrote: Hiya, I'm writing an app that let's my client upload images, the image html code is added to an XML file. Take a look at the image element below: item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 /]]/image nameBlue Ski Trousers/name price8.99/price /item Now, whenever PHP writes this to the XML files, it turns the and into lt; and gt; . which means it does not display on the webpage. How can I prevent this from happening ? str_replace? Does the xml string get passed to htmlentities() or a similar function before it is sent to the browser? That would explain the substitutions. I saw an xmlentities() variation mentioned somewhere. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi Bob, Nope the string doesn't get passed into any function. Here is the XML: _ ?xml version=1.0 encoding=UTF-8? clothes item Code=e1021 codee1021/code image![CDATA[img src=uploads/image1.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image1.jpg','Preview','width=680,height=520') /]]/image nameRed Jacket/name descAn adult sized red jacket/desc sizeadult/size price12.99/price /item item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image2.jpg','Preview','width=680,height=520') /]]/image nameBlue Ski Trousers/name descA pair of Blue Ski Trousers/desc sizechild/size price8.99/price /item /clothes Now the image tags I have written here I have done manually, but when I use PHP using DOM they come out like this (note the image element): item Code=e1024 codee1024/code imagelt;![CDATA[lt;img src=uploads/image4.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image4.jpg','Preview','width=680,height=520') /gt;]]gt;/image nameorange top/name descan orange jacket/desc sizelarge/size price14.50/price /item Matthew Croud Studio Obvious Print Solutions Limited Unit 3 Abbeygate Court Stockett Lane Maidstone Kent ME15 0PP T | 0845 094 9704 F | 0845 094 9705 www.obviousprint.com
Re: [PHP] Renaming a Directory
On 9/9/09 12:08 AM, Paul M Foster pa...@quillandmouse.com wrote: On Tue, Sep 08, 2009 at 05:39:43PM -0400, Floyd Resler wrote: How can I rename a directory with files in it? The rename function gives me a directory not empty error. I know I could do it be creating the directory, moving the files, and then deleting the old one. Is there an easier way? It sounds like, underneath, rename() is creating a new directory and then attempting to delete the old one, ignoring the files in the original directory. really? the test below seems to show that php rename() is happy to rename directories that are not empty. it even renames ones that contain files that it neither owns nor has any permissions for. that suggests it is just changing the name of the directory. so the error message floyd reported is still a mystery to me, assuming /bin/mv worked for the same old and new directories where php rename() failed. $ mkdir wwwdir $ sudo chown www:www wwwdir $ cd wwwdir $ sudo -u www mkdir testdir $ sudo -u www touch testdir/foo testdir/bar $ sudo -u www php -r echo rename('testdir','dirtest'); 1$ ls -la dirtest total 0 drwxr-xr-x 4 _www _www 136 Sep 9 09:57 . drwxr-xr-x 3 _www _www 102 Sep 9 09:57 .. -rw-r--r-- 1 _www _www0 Sep 9 09:57 bar -rw-r--r-- 1 _www _www0 Sep 9 09:57 foo $ sudo -u www chmod 000 dirtest/foo $ sudo -u www php -r echo rename('dirtest','testdir'); 1$ ls -la testdir total 0 drwxr-xr-x 4 _www _www 136 Sep 9 09:57 . drwxr-xr-x 3 _www _www 102 Sep 9 09:57 .. -rw-r--r-- 1 _www _www0 Sep 9 09:57 bar -- 1 _www _www0 Sep 9 09:57 foo $ sudo chown root:wheel testdir/foo $ sudo -u www -u www php -r echo rename('testdir','dirtest'); 1$ ls -la dirtest total 0 drwxr-xr-x 4 _www _www 136 Sep 9 09:57 . drwxr-xr-x 3 _www _www 102 Sep 9 09:57 .. -rw-r--r-- 1 _www _www 0 Sep 9 09:57 bar -- 1 root wheel0 Sep 9 09:57 foo $ php -v PHP 5.2.8 (cli) (built: Feb 5 2009 21:21:13) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies $ uname -v Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 $ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML. Prevent from turning into lt;
On Wed, 2009-09-09 at 14:46 +0100, Matthew Croud wrote: On 9 Sep 2009, at 14:36, Bob McConnell wrote: From: Bastien Koert On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croudm...@obviousdigital.com wrote: Hiya, I'm writing an app that let's my client upload images, the image html code is added to an XML file. Take a look at the image element below: item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 /]]/image nameBlue Ski Trousers/name price8.99/price /item Now, whenever PHP writes this to the XML files, it turns the and into lt; and gt; . which means it does not display on the webpage. How can I prevent this from happening ? str_replace? Does the xml string get passed to htmlentities() or a similar function before it is sent to the browser? That would explain the substitutions. I saw an xmlentities() variation mentioned somewhere. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi Bob, Nope the string doesn't get passed into any function. Here is the XML: _ ?xml version=1.0 encoding=UTF-8? clothes item Code=e1021 codee1021/code image![CDATA[img src=uploads/image1.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image1.jpg','Preview','width=680,height=520') /]]/image nameRed Jacket/name descAn adult sized red jacket/desc sizeadult/size price12.99/price /item item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image2.jpg','Preview','width=680,height=520') /]]/image nameBlue Ski Trousers/name descA pair of Blue Ski Trousers/desc sizechild/size price8.99/price /item /clothes Now the image tags I have written here I have done manually, but when I use PHP using DOM they come out like this (note the image element): item Code=e1024 codee1024/code imagelt;![CDATA[lt;img src=uploads/image4.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image4.jpg','Preview','width=680,height=520') /gt;]]gt;/image nameorange top/name descan orange jacket/desc sizelarge/size price14.50/price /item Matthew Croud Studio Obvious Print Solutions Limited Unit 3 Abbeygate Court Stockett Lane Maidstone Kent ME15 0PP T | 0845 094 9704 F | 0845 094 9705 www.obviousprint.com I've not experienced this with using any DOM functions, but if we can see your code it might help us. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql user session handler
good point, gabriel. i really need to stop procrastinating with the whole memcache project. perhaps i ought to postpone consideration of the session handler until i've learned something about memcache, which i need to do anyway. On 9/8/09 10:06 PM, Gabriel Sosa sosagabr...@gmail.com wrote: I'm our case we opt for memcache to store the sessions Mmc its soo much faster and you will have less net overhead because the simple protocol Also the configuration its easier. If you see in the php manual you only need to touch two lines in the php.ini On 9/8/09, Tom Worster f...@thefsb.org wrote: thanks, Devendra, that's pretty much the same as my handler. (though i can't figure Rich Smith's $sess_save_path global. do you know what is for?) but what i'm really interested in is people's experience in switching over to and using this kind of handler: pitfalls, gotchas, etc. or is it really as easy and simple as all these online articles i've read about it claim? or is that experience so hard won that people aren't keen to share it? -tom On 9/8/09 2:23 PM, Devendra Jadhav devendra...@gmail.com wrote: http://www.devshed.com/c/a/PHP/Storing-PHP-Sessions-in-a-Database/ On Tue, Sep 8, 2009 at 10:53 PM, Tom Worster f...@thefsb.org wrote: questions for those of you with a user session handler using mysql: did you write your own handler, write one based off some other you found (if so, which?), or are you using some available library (if so, which?)? and how do you feel about your implementation? satisfied? or are there improvements you'd like to have? and what serializer do you use? i have my own set of handler functions (less than 70 loc) which seem to work in simple testing. but, while i'd really like to have the sessions in the db for redundancy, i haven't had the courage to deploy it yet. i derived the code from something i found on the web. i trust everything i read on the internet ;-) -tom -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Renaming a Directory
Paul M Foster a écrit : I would have thought so, but the man pages didn't mention it. I haven't use mv in ages. Makes sense that it would work, though. Moving/renaming a file would just change the name, not the inode number, which is the real key to *nix file systems. Ashley said it, a directory is a file. But more, when you do a mv on a file, it don't rename. If the target is in the same filesystem, mv do a hard link on the source file, then unlink the original name. If you move accross filesystem, mv do a copy of the directory. If you don't believe me, get the source. -- Mickaël Wolff aka Lupus Michaelis http://lupusmic.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Class variable value lost
Hi, I have developed a listing site which is totally class based. Now when it authenticates a user login and set appropriate class variables to true and set user info in user class variables, value of all the set variables are lost when I forward the user to members page. When I check the the value on other page it is set to the default value of the class. Please help. Regard, Sumit
[PHP] Re: Class variable value lost
Sumit Sharma wrote: Hi, I have developed a listing site which is totally class based. Now when it authenticates a user login and set appropriate class variables to true and set user info in user class variables, value of all the set variables are lost when I forward the user to members page. When I check the the value on other page it is set to the default value of the class. Please help. Regard, Sumit You needs to pass the object to the next page. Look into sessions. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Class variable value lost
On Wed, 2009-09-09 at 10:36 -0500, Shawn McKenzie wrote: Sumit Sharma wrote: Hi, I have developed a listing site which is totally class based. Now when it authenticates a user login and set appropriate class variables to true and set user info in user class variables, value of all the set variables are lost when I forward the user to members page. When I check the the value on other page it is set to the default value of the class. Please help. Regard, Sumit You needs to pass the object to the next page. Look into sessions. -- Thanks! -Shawn http://www.spidean.com The object only exists for that instance of the script, so when the user navigates to the next page, the object is freed up from the memory. There are a couple of ways you could get round this: * don't navigate away from the page, and use AJAX calls to update parts of the page for the user (bad imho, as it relies on Javascript) * use sessions like Shawn recommended If you use sessions, you can store the objects themselves as variables into the session. You should be careful with this, as you may not want too many sessions open with large objects in them as, depending on your server setup, sessions could last quite a while, and there may also be a limit on the amount of memory reserved for sessions. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML. Prevent from turning into lt;
On 9 Sep 2009, at 16:37, Ashley Sheridan wrote: On Wed, 2009-09-09 at 15:14 +0100, Matthew Croud wrote: On 9 Sep 2009, at 15:09, Ashley Sheridan wrote: On Wed, 2009-09-09 at 14:46 +0100, Matthew Croud wrote: On 9 Sep 2009, at 14:36, Bob McConnell wrote: From: Bastien Koert On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croudm...@obviousdigital.com wrote: Hiya, I'm writing an app that let's my client upload images, the image html code is added to an XML file. Take a look at the image element below: item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 /]]/image nameBlue Ski Trousers/name price8.99/price /item Now, whenever PHP writes this to the XML files, it turns the and into lt; and gt; . which means it does not display on the webpage. How can I prevent this from happening ? str_replace? Does the xml string get passed to htmlentities() or a similar function before it is sent to the browser? That would explain the substitutions. I saw an xmlentities() variation mentioned somewhere. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi Bob, Nope the string doesn't get passed into any function. Here is the XML: _ ?xml version=1.0 encoding=UTF-8? clothes item Code=e1021 codee1021/code image![CDATA[img src=uploads/image1.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image1.jpg','Preview','width=680,height=520') /]]/image nameRed Jacket/name descAn adult sized red jacket/desc sizeadult/size price12.99/price /item item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image2.jpg','Preview','width=680,height=520') /]]/image nameBlue Ski Trousers/name descA pair of Blue Ski Trousers/desc sizechild/size price8.99/price /item /clothes Now the image tags I have written here I have done manually, but when I use PHP using DOM they come out like this (note the image element): item Code=e1024 codee1024/code imagelt;![CDATA[lt;img src=uploads/image4.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image4.jpg','Preview','width=680,height=520') /gt;]]gt;/image nameorange top/name descan orange jacket/desc sizelarge/size price14.50/price /item Matthew Croud Studio Obvious Print Solutions Limited Unit 3 Abbeygate Court Stockett Lane Maidstone Kent ME15 0PP T | 0845 094 9704 F | 0845 094 9705 www.obviousprint.com I've not experienced this with using any DOM functions, but if we can see your code it might help us. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Well i'll pop the PHP down here, i'll trim it as much as i can: $code = $_POST['code']; $name = $_POST['name']; $desc = $_POST['desc']; $size = $_POST['size']; $price = $_POST['price']; #load an XML document into the DOM $dom = new DomDocument(); $dom - load(items.xml); #create elements $Xitem = $dom - createElement(item); $Xcode = $dom - createElement(code); $Ximage = $dom - createElement(image); $Xname = $dom - createElement(name); $Xdesc = $dom - createElement(desc); $Xsize = $dom - createElement(size); $Xprice = $dom - createElement(price); #create text nodes $Xcodetext = $dom - createTextNode($code); $Ximagetext = $dom - createTextNode( ![CDATA[img src=\uploads/ $UploadName\ alt=\Homepage Image\ width=\124\ height=\70\ border=\1\ onclick=\MM_openBrWindow('uploads/ $UploadName','Preview','width=680,height=520')\ /]] ); $Xnametext = $dom - createTextNode($name); $Xdesctext = $dom - createTextNode($desc); $Xsizetext =$dom - createTextNode($size); $Xpricetext =$dom - createTextNode($price); #append the text nodes to the inner nested elements $Xcode - appendChild($Xcodetext); $Ximage - appendChild($Ximagetext); $Xname - appendChild($Xnametext); $Xdesc - appendChild($Xdesctext); $Xsize- appendChild($Xsizetext); $Xprice- appendChild($Xpricetext); #append the inner nested elements to the item element $Xitem - appendChild($Xcode); $Xitem - appendChild($Ximage); $Xitem - appendChild($Xname); $Xitem - appendChild($Xdesc); $Xitem - appendChild($Xsize); $Xitem - appendChild($Xprice); $Xitem - setAttribute(Code,$code); #append the title element to the root element $dom - documentElement - appendChild($Xitem); #create a new enlarged xml document $dom - save(items.xml); _ It looks like it's because you are creating an image object by appending a text node inside CDATA to it. My guess is
Fwd: [PHP] Re: Class variable value lost
What I have done is declared one User class in a separate file and created its object there only. After this included this file in all other file which are using its object. So the object is creating only once and included in every other file only once. Now when I over write its variable it value get lost when I send the user in other file. The confusion is if I have created only one object of a class and used the same object through out the site how its value can get lost and I think this is a separate issue than setting $_SESSION variables. -- Forwarded message -- From: Ashley Sheridan a...@ashleysheridan.co.uk Date: Wed, Sep 9, 2009 at 9:14 PM Subject: Re: [PHP] Re: Class variable value lost To: Shawn McKenzie nos...@mckenzies.net Cc: Sumit Sharma sumitp...@gmail.com, PHP General Mailing List php-general@lists.php.net On Wed, 2009-09-09 at 10:36 -0500, Shawn McKenzie wrote: Sumit Sharma wrote: Hi, I have developed a listing site which is totally class based. Now when it authenticates a user login and set appropriate class variables to true and set user info in user class variables, value of all the set variables are lost when I forward the user to members page. When I check the the value on other page it is set to the default value of the class. Please help. Regard, Sumit You needs to pass the object to the next page. Look into sessions. -- Thanks! -Shawn http://www.spidean.com The object only exists for that instance of the script, so when the user navigates to the next page, the object is freed up from the memory. There are a couple of ways you could get round this: * don't navigate away from the page, and use AJAX calls to update parts of the page for the user (bad imho, as it relies on Javascript) * use sessions like Shawn recommended If you use sessions, you can store the objects themselves as variables into the session. You should be careful with this, as you may not want too many sessions open with large objects in them as, depending on your server setup, sessions could last quite a while, and there may also be a limit on the amount of memory reserved for sessions. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Re: Class variable value lost
On Wed, Sep 9, 2009 at 11:58 AM, Sumit Sharma sumitp...@gmail.com wrote: What I have done is declared one User class in a separate file and created its object there only. After this included this file in all other file which are using its object. So the object is creating only once and included in every other file only once. Now when I over write its variable it value get lost when I send the user in other file. The confusion is if I have created only one object of a class and used the same object through out the site how its value can get lost and I think this is a separate issue than setting $_SESSION variables. This happens because your object is destroyed as soon as PHP finishes serving the request. That's the way the web was designed. If you want your object to persist from one request to another, YOU have to persist it. There are lots of ways to do that. Storing your object in a $_SESSION variable is one of those ways. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML. Prevent from turning into lt;
On Wed, 2009-09-09 at 16:51 +0100, Matthew Croud wrote: On 9 Sep 2009, at 16:37, Ashley Sheridan wrote: On Wed, 2009-09-09 at 15:14 +0100, Matthew Croud wrote: On 9 Sep 2009, at 15:09, Ashley Sheridan wrote: On Wed, 2009-09-09 at 14:46 +0100, Matthew Croud wrote: On 9 Sep 2009, at 14:36, Bob McConnell wrote: From: Bastien Koert On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croudm...@obviousdigital.com wrote: Hiya, I'm writing an app that let's my client upload images, the image html code is added to an XML file. Take a look at the image element below: item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 /]]/image nameBlue Ski Trousers/name price8.99/price /item Now, whenever PHP writes this to the XML files, it turns the and into lt; and gt; . which means it does not display on the webpage. How can I prevent this from happening ? str_replace? Does the xml string get passed to htmlentities() or a similar function before it is sent to the browser? That would explain the substitutions. I saw an xmlentities() variation mentioned somewhere. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi Bob, Nope the string doesn't get passed into any function. Here is the XML: _ ?xml version=1.0 encoding=UTF-8? clothes item Code=e1021 codee1021/code image![CDATA[img src=uploads/image1.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image1.jpg','Preview','width=680,height=520') /]]/image nameRed Jacket/name descAn adult sized red jacket/desc sizeadult/size price12.99/price /item item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image2.jpg','Preview','width=680,height=520') /]]/image nameBlue Ski Trousers/name descA pair of Blue Ski Trousers/desc sizechild/size price8.99/price /item /clothes Now the image tags I have written here I have done manually, but when I use PHP using DOM they come out like this (note the image element): item Code=e1024 codee1024/code imagelt;![CDATA[lt;img src=uploads/image4.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image4.jpg','Preview','width=680,height=520') /gt;]]gt;/image nameorange top/name descan orange jacket/desc sizelarge/size price14.50/price /item Matthew Croud Studio Obvious Print Solutions Limited Unit 3 Abbeygate Court Stockett Lane Maidstone Kent ME15 0PP T | 0845 094 9704 F | 0845 094 9705 www.obviousprint.com I've not experienced this with using any DOM functions, but if we can see your code it might help us. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Well i'll pop the PHP down here, i'll trim it as much as i can: $code = $_POST['code']; $name = $_POST['name']; $desc = $_POST['desc']; $size = $_POST['size']; $price = $_POST['price']; #load an XML document into the DOM $dom = new DomDocument(); $dom - load(items.xml); #create elements $Xitem = $dom - createElement(item); $Xcode = $dom - createElement(code); $Ximage = $dom - createElement(image); $Xname = $dom - createElement(name); $Xdesc = $dom - createElement(desc); $Xsize = $dom - createElement(size); $Xprice = $dom - createElement(price); #create text nodes $Xcodetext = $dom - createTextNode($code); $Ximagetext = $dom - createTextNode( ![CDATA[img src=\uploads/ $UploadName\ alt=\Homepage Image\ width=\124\ height=\70\ border=\1\ onclick=\MM_openBrWindow('uploads/ $UploadName','Preview','width=680,height=520')\ /]] ); $Xnametext = $dom - createTextNode($name); $Xdesctext = $dom - createTextNode($desc); $Xsizetext =$dom - createTextNode($size); $Xpricetext =$dom - createTextNode($price); #append the text nodes to the inner nested elements $Xcode - appendChild($Xcodetext); $Ximage - appendChild($Ximagetext); $Xname - appendChild($Xnametext); $Xdesc - appendChild($Xdesctext); $Xsize- appendChild($Xsizetext); $Xprice- appendChild($Xpricetext); #append the inner nested elements to the item element $Xitem - appendChild($Xcode); $Xitem - appendChild($Ximage); $Xitem - appendChild($Xname); $Xitem - appendChild($Xdesc); $Xitem - appendChild($Xsize); $Xitem -
Re: [PHP] XML. Prevent from turning into lt;
You need to look at disable_output_escaping at http://www.w3.org/TR/xslt#disable-output-escaping -- Tony Marston http://www.tonymarston.net http://www.radicore.org Matthew Croud m...@obviousdigital.com wrote in message news:2c4840c2-45db-4d6c-b5fa-2cb15b171...@obviousdigital.com... On 9 Sep 2009, at 14:26, Bastien Koert wrote: On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croudm...@obviousdigital.com wrote: Hiya, I'm writing an app that let's my client upload images, the image html code is added to an XML file. Take a look at the image element below: item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 /]]/image nameBlue Ski Trousers/name price8.99/price /item Now, whenever PHP writes this to the XML files, it turns the and into lt; and gt; . which means it does not display on the webpage. How can I prevent this from happening ? Many thanks, Matt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php str_replace? -- Bastien Cat, the other other white meat I've tried that but no matter what i do in the PHP side of things, as soon as I save that XML the conversion takes place. Should the XML be encoded in any way, is there a setting somewhere that prevents this ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match()
Good Afternoon. This shouldn't be too complicated, but I can't come up with a solution for the problem right now. It's about RegEx in PHP (5.2) Is there a way to capture ALL sub elements of an expression like preg_match('@a(?[0-9])*b@' ,a2345678b , $matches); ?? This would produce (below) whereas I'd like to get all the elements (2-8) as an array entry each . ([1]=2, [2]=3 .) Result: array(2) { [0]= array(1) { [0]= string(9) a2345678b } [1]= array(1) { [0]= string(1) 8 } } preg_match_all doesn't do the trick. The Expression I want to use is @prim_states[\s]*\((?num[0-9\s]*)(prim_state[\s]*\((?flag[a-fA-F0-9\s]*) tex_idxs[\s]*\(([0-9\s]*)\)([0-9\s]*)\)[\s]*)*\)@ as I'm trying to parse a 3d Model File, that contains data in the form of prim_states ( 51 prim_state ( 2 tex_idxs ( 1 2 ) 0 3 0 0 1 ) prim_state ( 3 tex_idxs ( 1 2 ) 0 0 1 0 1 ) prim_state ( 3 tex_idxs ( 1 2 ) 0 4 1 0 1 ) [.] ) Thank You! Regards, Jan
Re: [PHP] preg_match()
On Wed, 2009-09-09 at 18:18 +0200, Jan Reiter wrote: Good Afternoon. This shouldn't be too complicated, but I can't come up with a solution for the problem right now. It's about RegEx in PHP (5.2) Is there a way to capture ALL sub elements of an expression like preg_match('@a(?[0-9])*b@' ,a2345678b , $matches); ?? This would produce (below) whereas I'd like to get all the elements (2-8) as an array entry each . ([1]=2, [2]=3 .) Result: array(2) { [0]= array(1) { [0]= string(9) a2345678b } [1]= array(1) { [0]= string(1) 8 } } preg_match_all doesn't do the trick. The Expression I want to use is @prim_states[\s]*\((?num[0-9\s]*)(prim_state[\s]*\((?flag[a-fA-F0-9\s]*) tex_idxs[\s]*\(([0-9\s]*)\)([0-9\s]*)\)[\s]*)*\)@ as I'm trying to parse a 3d Model File, that contains data in the form of prim_states ( 51 prim_state ( 2 tex_idxs ( 1 2 ) 0 3 0 0 1 ) prim_state ( 3 tex_idxs ( 1 2 ) 0 0 1 0 1 ) prim_state ( 3 tex_idxs ( 1 2 ) 0 4 1 0 1 ) [.] ) Thank You! Regards, Jan If your example is indicative of what you need, then couldn't you just loop through all the elements inside of the match as it will be a contiguous string of numbers. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg_match()
Not quite, I'm sorry. As the outer expression prim_states( [...] ) captures, the repetitive elements inside prim_state( [...] ) overwrite each other in the matches array. Of course I could get the first entry in matches, and search it again with preg_match_all(), but that is what I'm trying to avoid. But maybe that's what I have to after all if there is no other way. Thanks Regards, Jan -Original Message- From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Wednesday, September 09, 2009 6:21 PM To: Jan Reiter Cc: php-general@lists.php.net Subject: Re: [PHP] preg_match() On Wed, 2009-09-09 at 18:18 +0200, Jan Reiter wrote: Good Afternoon. This shouldn't be too complicated, but I can't come up with a solution for the problem right now. It's about RegEx in PHP (5.2) Is there a way to capture ALL sub elements of an expression like preg_match('@a(?[0-9])*b@' ,a2345678b , $matches); ?? This would produce (below) whereas I'd like to get all the elements (2-8) as an array entry each . ([1]=2, [2]=3 .) Result: array(2) { [0]= array(1) { [0]= string(9) a2345678b } [1]= array(1) { [0]= string(1) 8 } } preg_match_all doesn't do the trick. The Expression I want to use is @prim_states[\s]*\((?num[0-9\s]*)(prim_state[\s]*\((?flag[a-fA-F0-9\s]*) tex_idxs[\s]*\(([0-9\s]*)\)([0-9\s]*)\)[\s]*)*\)@ as I'm trying to parse a 3d Model File, that contains data in the form of prim_states ( 51 prim_state ( 2 tex_idxs ( 1 2 ) 0 3 0 0 1 ) prim_state ( 3 tex_idxs ( 1 2 ) 0 0 1 0 1 ) prim_state ( 3 tex_idxs ( 1 2 ) 0 4 1 0 1 ) [.] ) Thank You! Regards, Jan If your example is indicative of what you need, then couldn't you just loop through all the elements inside of the match as it will be a contiguous string of numbers. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Eingehende eMail ist virenfrei. Von AVG überprüft - www.avg.de Version: 8.5.409 / Virendatenbank: 270.13.71/2336 - Ausgabedatum: 09/08/09 20:45:00 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: preg_match()
Jan Reiter wrote: Good Afternoon. This shouldn't be too complicated, but I can't come up with a solution for the problem right now. It's about RegEx in PHP (5.2) Is there a way to capture ALL sub elements of an expression like preg_match('@a(?[0-9])*b@' ,a2345678b , $matches); ?? This would produce (below) whereas I'd like to get all the elements (2-8) as an array entry each . ([1]=2, [2]=3 .) AFAIK, you would need to know how many digits are there and use that many capture groups (), because you only have one capture group which will be overwritten each iteration. An alternative for your simple example above would be to do: preg_match('@a([0-9]+)b@' ,a2345678b , $matches); --then-- print_r(str_split($matches[1])); To do this multiple times in a large string you would need: preg_match_all('@a([0-9]+)b@' ,a2345678b , $matches); foreach($matches[1] as $match) { print_r(str_split($match)); } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg_match()
Thanks! Thats about what I'm doing right now. function parse_prim_states($in) { preg_match('@prim_states[\s]*\((?number[0-9\s]*)@' ,$in , $matches); $this-num_prim_states = (int)$matches['number']; preg_match_all('@prim_state[\s]*\((?flag1[a-fA-F0-9\s]*)tex_idxs[\s]*\((? texidx[0-9\s]*)\)(?flag2[0-9\s]*)\)@' ,$in , $matches); for($i=0;$i$this-num_prim_states;$i++) { $this-add_prim_state($matches['flag1'][$i],$matches['flag2'][$i],$matches[' texid'][$i]); } unset($matches); return true; } Regards -Original Message- From: Shawn McKenzie [mailto:nos...@mckenzies.net] Sent: Wednesday, September 09, 2009 7:57 PM To: Jan Reiter Cc: php-general@lists.php.net Subject: [PHP] Re: preg_match() Jan Reiter wrote: Good Afternoon. This shouldn't be too complicated, but I can't come up with a solution for the problem right now. It's about RegEx in PHP (5.2) Is there a way to capture ALL sub elements of an expression like preg_match('@a(?[0-9])*b@' ,a2345678b , $matches); ?? This would produce (below) whereas I'd like to get all the elements (2-8) as an array entry each . ([1]=2, [2]=3 .) AFAIK, you would need to know how many digits are there and use that many capture groups (), because you only have one capture group which will be overwritten each iteration. An alternative for your simple example above would be to do: preg_match('@a([0-9]+)b@' ,a2345678b , $matches); --then-- print_r(str_split($matches[1])); To do this multiple times in a large string you would need: preg_match_all('@a([0-9]+)b@' ,a2345678b , $matches); foreach($matches[1] as $match) { print_r(str_split($match)); } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Eingehende eMail ist virenfrei. Von AVG überprüft - www.avg.de Version: 8.5.409 / Virendatenbank: 270.13.71/2336 - Ausgabedatum: 09/09/09 06:53:00 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Class variable value lost
On Wed, Sep 9, 2009 at 12:58 PM, Sumit Sharma sumitp...@gmail.com wrote: What I have done is declared one User class in a separate file and created its object there only. After this included this file in all other file which are using its object. So the object is creating only once and included in every other file only once. Now when I over write its variable it value get lost when I send the user in other file. The confusion is if I have created only one object of a class and used the same object through out the site how its value can get lost and I think this is a separate issue than setting $_SESSION variables. -- Forwarded message -- From: Ashley Sheridan a...@ashleysheridan.co.uk Date: Wed, Sep 9, 2009 at 9:14 PM Subject: Re: [PHP] Re: Class variable value lost To: Shawn McKenzie nos...@mckenzies.net Cc: Sumit Sharma sumitp...@gmail.com, PHP General Mailing List php-general@lists.php.net On Wed, 2009-09-09 at 10:36 -0500, Shawn McKenzie wrote: Sumit Sharma wrote: Hi, I have developed a listing site which is totally class based. Now when it authenticates a user login and set appropriate class variables to true and set user info in user class variables, value of all the set variables are lost when I forward the user to members page. When I check the the value on other page it is set to the default value of the class. Please help. Regard, Sumit You needs to pass the object to the next page. Look into sessions. -- Thanks! -Shawn http://www.spidean.com The object only exists for that instance of the script, so when the user navigates to the next page, the object is freed up from the memory. There are a couple of ways you could get round this: * don't navigate away from the page, and use AJAX calls to update parts of the page for the user (bad imho, as it relies on Javascript) * use sessions like Shawn recommended If you use sessions, you can store the objects themselves as variables into the session. You should be careful with this, as you may not want too many sessions open with large objects in them as, depending on your server setup, sessions could last quite a while, and there may also be a limit on the amount of memory reserved for sessions. Thanks, Ash http://www.ashleysheridan.co.uk Unless you store the object state your application will not be able to remember it. There is a design pattern specially designed for this, the Memento Pattern ( http://en.wikipedia.org/wiki/Memento_pattern) There are many ways to persist an object: sessions, xml, text files, databases. Pick the one that fits better and you'll be fine. -- Martin Scotta
Re: Fwd: [PHP] Re: Class variable value lost
Sumit Sharma wrote: What I have done is declared one User class in a separate file and created its object there only. After this included this file in all other file which are using its object. So the object is creating only once and included in every other file only once. Now when I over write its variable it value get lost when I send the user in other file. The confusion is if I have created only one object of a class and used the same object through out the site how its value can get lost and I think this is a separate issue than setting $_SESSION variables. This is roughly how it works: ?php //user.php $user = new User(); class User { //some stuff } ? ?php //file a.php //NEW $user object is created include('user.php'); //do some stuff //$user is DESTROYED, end of script ? ?php //file b.php //NEW $user object is created include('user.php'); //do some stuff //$user is DESTROYED, end of script ? If you want to keep the first $user object and persist it across pages, then you can many different things, but you need to put it in the session. One example (you could also write a session class to take care of all of your session stuff): ?php //user.php class User { //some stuff } ? ?php //file a.php include('user.php'); session_start(); if(isset($_SESSION['user'])) { $user = unserialize($_SESSION['user']); } else { $user = new User(); } //do some stuff //save $user to session $_SESSION['user'] = serialize($user); //$user is DESTROYED, end of script, but $_SESSION['user'] persists ? ?php //file b.php include('user.php'); session_start(); if(isset($_SESSION['user'])) { $user = unserialize($_SESSION['user']); } else { $user = new User(); } //do some stuff //save $user to session $_SESSION['user'] = serialize($user); //$user is DESTROYED, end of script, but $_SESSION['user'] persists ? -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] script failing at same line
My solution was to add a table to my database, and add an insert job id into the table after the line that is causing the problem. When I submit the script I use setTimeout to run an AJAX query of the table 5 seconds later. If the line has failed the job id will not be in the table and I alert the user. It works - and some day I hope to fix the software problem and make this unnecessary. Thanks for the update -- that's about how I would have approached it too. I wonder, in general, if fixing the underlying problem is even practical or worth the investment of time. IIRC the problem was in third-party code -- and it seems to me that making your own code robust enough to handle failures in third-party libraries (as you just did) is a really fruitful use of your time; fixing the library itself, maybe not so much. I guess it depends on how it all affects your end users. Ben
Re: [PHP] Re: Class variable value lost
The object only exists for that instance of the script, so when the user navigates to the next page, the object is freed up from the memory. There are a couple of ways you could get round this: * don't navigate away from the page, and use AJAX calls to update parts of the page for the user (bad imho, as it relies on Javascript) I think any AJAX-based approached would run into the same difficulty, because each AJAX call is a separate HTTP request from the one that originally loaded the page (and from every other AJAX call). Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] dns lookups only half working in chroot
Hey guys, I am cross-posting this to the PHP and the PHP-FPM lists, because both are applicable in my opinion. I have got a strange problem with my php-fpm chrooted PHP environment. PHP is chrooted to /var/www/. /var/www/etc looks like this: # ls -al /var/www/etc/ insgesamt 20 drwxr-xr-x 2 root root 4096 9. Sep 20:33 . drwxr-xr-x 5 root root 4096 9. Sep 20:10 .. -rw-r--r-- 1 root root 265 9. Sep 20:12 hosts -rw-r--r-- 1 root root 513 9. Sep 20:23 nsswitch.conf -rw-r--r-- 1 root root 52 9. Sep 20:11 resolv.conf I do run the following script: ?php echo gethostbyname('www.google.de').\n; print_r(dns_get_record('www.google.de', DNS_A)).\n; ? Which strangely outputs this: www.google.de Array ( [0] = Array ( [host] = www.l.google.com [type] = A [ip] = 74.125.43.147 [class] = IN [ttl] = 172 ) [1] = Array ( [host] = www.l.google.com [type] = A [ip] = 74.125.43.99 [class] = IN [ttl] = 172 ) [2] = I don't understand why the first lookup fails, but the second one succeeds. Unfortunately thinks like fsockopen() seem to use the same technique as gethostbyname(), so they don't work either. Any pointers would be appreciated! Regards, Samy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Encrypt then decrypt yields extra dots at end
I thought this code: $enc=mcrypt_ecb(MCRYPT_RIJNDAEL_256,salt123,encrypt_me,MCRYPT_ENCRYPT); $dec=mcrypt_ecb(MCRYPT_RIJNDAEL_256,salt123,$enc,MCRYPT_DECRYPT); echo $dec; would yield encrypt_me. The actual result is encrypt_me.. (bunch of extra dots). Why, and how do I fix it? The manual says that mcrypt_ecb() is deprecated and recommends mcrypt_generic() instead. Its page mentions that the input string will be padded to the next-highest multiple of the current block size, and points out: 'Note the string returned by mdecrypt_generic() will be [padded] as well...use rtrim($str, \0) to remove the padding' http://us3.php.net/manual/en/function.mcrypt-generic.php So I would guess that mcrypt_ecb() operates in a similar way, which can be solved with rtrim(). Does your script actually echo . characters (ASCII 0x2E), or is that your terminal's way of representing some non-printable character? It would surprise me if mcrypt_ecb() used the . character as its pad, but maybe it does. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] XML. Prevent from turning into lt;
give it a try with PDATA instead of CDATA and see what happns Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1252512252.2961.40.ca...@localhost... On Wed, 2009-09-09 at 16:51 +0100, Matthew Croud wrote: On 9 Sep 2009, at 16:37, Ashley Sheridan wrote: On Wed, 2009-09-09 at 15:14 +0100, Matthew Croud wrote: On 9 Sep 2009, at 15:09, Ashley Sheridan wrote: On Wed, 2009-09-09 at 14:46 +0100, Matthew Croud wrote: On 9 Sep 2009, at 14:36, Bob McConnell wrote: From: Bastien Koert On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croudm...@obviousdigital.com wrote: Hiya, I'm writing an app that let's my client upload images, the image html code is added to an XML file. Take a look at the image element below: item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 /]]/image nameBlue Ski Trousers/name price8.99/price /item Now, whenever PHP writes this to the XML files, it turns the and into lt; and gt; . which means it does not display on the webpage. How can I prevent this from happening ? str_replace? Does the xml string get passed to htmlentities() or a similar function before it is sent to the browser? That would explain the substitutions. I saw an xmlentities() variation mentioned somewhere. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi Bob, Nope the string doesn't get passed into any function. Here is the XML: _ ?xml version=1.0 encoding=UTF-8? clothes item Code=e1021 codee1021/code image![CDATA[img src=uploads/image1.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image1.jpg','Preview','width=680,height=520') /]]/image nameRed Jacket/name descAn adult sized red jacket/desc sizeadult/size price12.99/price /item item Code=e1022 codee1022/code image![CDATA[img src=uploads/image2.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image2.jpg','Preview','width=680,height=520') /]]/image nameBlue Ski Trousers/name descA pair of Blue Ski Trousers/desc sizechild/size price8.99/price /item /clothes Now the image tags I have written here I have done manually, but when I use PHP using DOM they come out like this (note the image element): item Code=e1024 codee1024/code imagelt;![CDATA[lt;img src=uploads/image4.jpg alt=Homepage Image width=124 height=70 border=1 onclick=MM_openBrWindow('uploads/ image4.jpg','Preview','width=680,height=520') /gt;]]gt;/image nameorange top/name descan orange jacket/desc sizelarge/size price14.50/price /item Matthew Croud Studio Obvious Print Solutions Limited Unit 3 Abbeygate Court Stockett Lane Maidstone Kent ME15 0PP T | 0845 094 9704 F | 0845 094 9705 www.obviousprint.com I've not experienced this with using any DOM functions, but if we can see your code it might help us. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Well i'll pop the PHP down here, i'll trim it as much as i can: $code = $_POST['code']; $name = $_POST['name']; $desc = $_POST['desc']; $size = $_POST['size']; $price = $_POST['price']; #load an XML document into the DOM $dom = new DomDocument(); $dom - load(items.xml); #create elements $Xitem = $dom - createElement(item); $Xcode = $dom - createElement(code); $Ximage = $dom - createElement(image); $Xname = $dom - createElement(name); $Xdesc = $dom - createElement(desc); $Xsize = $dom - createElement(size); $Xprice = $dom - createElement(price); #create text nodes $Xcodetext = $dom - createTextNode($code); $Ximagetext = $dom - createTextNode( ![CDATA[img src=\uploads/ $UploadName\ alt=\Homepage Image\ width=\124\ height=\70\ border=\1\ onclick=\MM_openBrWindow('uploads/ $UploadName','Preview','width=680,height=520')\ /]] ); $Xnametext = $dom - createTextNode($name); $Xdesctext = $dom - createTextNode($desc); $Xsizetext =$dom - createTextNode($size); $Xpricetext =$dom - createTextNode($price); #append the text nodes to the inner nested elements $Xcode - appendChild($Xcodetext); $Ximage - appendChild($Ximagetext); $Xname - appendChild($Xnametext); $Xdesc -
Re: [PHP] dns lookups only half working in chroot
?php echo gethostbyname('www.google.de').\n; print_r(dns_get_record('www.google.de', DNS_A)).\n; ? [8] I don't understand why the first lookup fails, but the second one succeeds. Unfortunately thinks like fsockopen() seem to use the same technique as gethostbyname(), so they don't work either. Any pointers would be appreciated! PHP's gethostbyname() is a wrapper for the system call of the same name, which may attempt to resolve the name using local mechanisms (/etc/hosts, perhaps an internal cache, etc.) before resorting to a DNS query. I've never studied any particular implementation of gethostbyname(), but I wouldn't be surprised to find that in some implementations it doesn't actually query DNS at all, but simply hands off the name to another mechanism that queries DNS. PHP's dns_get_record(), on the other hand, queries DNS using the resolver(3) system calls. All it needs is a network connection and a valid DNS server address. So that should help explain why one can work while the other doesn't. Not sure why gethostbyname() fails in your chroot environment, though. I've seen situations where this has happened on my internal network, but only fake hostnames that ended in .local were affected. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] new php script and sqlite
I was under the impression that sqlite2 was supported widely by PHP, but sqlite3 seems only to be enabled on php 5.3.0 by default. My concern now is actually that users may find that their hosting service providers don't provide sqlite3 out of the box. PDO seems to support both versions: http://us.php.net/manual/en/ref.pdo-sqlite.connection.php So if it's practical to restrict yourself to features that are available in both versions, you could probably do something like this: $db_file = 'filename'; $dbh = null; try { // prefer sqlite3 if available $dbh = new PDO('sqlite:$db_file'); } catch (PDOException $e) { // verify that error occurred because sqlite3 is not supported try { $dbh = new PDO('sqlite2:$db_file'); } catch (PDOException $e) { // bail out gracefully } } Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Little perl help?
Hey all, I know this is a PHP list, but I could use a bit of Perl help, a language which just does not fit in my C/C++/Java/PHP trained brain. A directory is created with the following: mkdir($img_dir,$CHMOD_ON_FOLDER_CREATE); I need to replace spaces with the underscore character so the directory name contains no spaces, so I tried preceding it with $img_dir =~ s/ /_/g; Which did nothing. Can someone help here? Much thanks, Skip -- Skip Evans Big Sky Penguin, LLC 503 S Baldwin St, #1 Madison WI 53703 608.250.2720 http://bigskypenguin.com Those of you who believe in telekinesis, raise my hand. -- Kurt Vonnegut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] new php script and sqlite
$dbh = new PDO('sqlite:$db_file'); [8] $dbh = new PDO('sqlite2:$db_file'); But with double-quotes, not single-quotes. ;-) Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [SPAM] [PHP] Little perl help?
My Bad. It looks like I had some code in the wrong place. Will try again. Skip m...@elysianfieldssoftware.com wrote: Skip, That *should* work. The below works on my Linux box. $img_dir=This is an dir name with spaces; $img_dir =~ s/ /_/g; printf(%s\n,$img_dir); mkdir($img_dir,$CHMOD_ON_FOLDER_CREATE); Is there something else you're not posting, or maybe I'm not understanding? Always glad to help a fellow cheesehead. Regards, Matt Flaig Elysian Fields Software, L.L.C. Original Message Subject: [SPAM] [PHP] Little perl help? From: Skip Evans s...@bigskypenguin.com Date: Wed, September 09, 2009 3:35 pm To: php-general@lists.php.net php-general@lists.php.net Hey all, I know this is a PHP list, but I could use a bit of Perl help, a language which just does not fit in my C/C++/Java/PHP trained brain. A directory is created with the following: mkdir($img_dir,$CHMOD_ON_FOLDER_CREATE); I need to replace spaces with the underscore character so the directory name contains no spaces, so I tried preceding it with $img_dir =~ s/ /_/g; Which did nothing. Can someone help here? Much thanks, Skip -- Skip Evans Big Sky Penguin, LLC 503 S Baldwin St, #1 Madison WI 53703 608.250.2720 http://bigskypenguin.com Those of you who believe in telekinesis, raise my hand. -- Kurt Vonnegut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Skip Evans Big Sky Penguin, LLC 503 S Baldwin St, #1 Madison WI 53703 608.250.2720 http://bigskypenguin.com Those of you who believe in telekinesis, raise my hand. -- Kurt Vonnegut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Performance of while(true) loop
Hey list, I have a php cli script that listens on a UDP socket and, when data is sent to the socket, the script inserts it into a database. I'm using the real BSD socket functions, not fsock. The script runs socket_create(), then socket_bind(). Then it starts a while(TRUE) loop. Within the loop, it runs socket_recvfrom(). I have it running 24/7 inside a screen window. I'm curious as to the cpu/memory/etc usage of a while(true) loop. The `top` command shows that the process is in the sbwait state (the OS is FreeBSD). I'm contemplating adding a usleep or even a sleep inside to loop. Would this be beneficial? I'm not too sure of how the internals of PHP work in terms of loops and such. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of while(true) loop
On Wed, Sep 9, 2009 at 10:32 PM, APseudoUtopia apseudouto...@gmail.com wrote: Hey list, I have a php cli script that listens on a UDP socket and, when data is sent to the socket, the script inserts it into a database. I'm using the real BSD socket functions, not fsock. The script runs socket_create(), then socket_bind(). Then it starts a while(TRUE) loop. Within the loop, it runs socket_recvfrom(). I have it running 24/7 inside a screen window. I'm curious as to the cpu/memory/etc usage of a while(true) loop. The `top` command shows that the process is in the sbwait state (the OS is FreeBSD). I'm contemplating adding a usleep or even a sleep inside to loop. Would this be beneficial? I'm not too sure of how the internals of PHP work in terms of loops and such. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Is your socket blocking? If so, what's the timeout? while(true) { //wait for socket timeout } is the same as: while(true) { //read nothing from socket and sleep } Without the usleep(), the loop is going to loop as fast as your CPU will let it - meaning 100% CPU usage, all the time, at least in linux, although I'm pretty sure BSD would behave the same. As far as I'm aware, sockets in PHP behave almost identically to the way that they behave in C. I had an asynchronous TCP server written with the socket_* functions and noticed that the while(true) loop used 100% of the CPU because of the nonblocking sockets in use, but a usleep() solved that quite easily. Using blocking sockets with socket_select and a sane timeout relieved the high CPU usage as well. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of while(true) loop
On Wed, Sep 9, 2009 at 10:39 PM, Eddie Drapkinoorza...@gmail.com wrote: On Wed, Sep 9, 2009 at 10:32 PM, APseudoUtopia apseudouto...@gmail.com wrote: Hey list, I have a php cli script that listens on a UDP socket and, when data is sent to the socket, the script inserts it into a database. I'm using the real BSD socket functions, not fsock. The script runs socket_create(), then socket_bind(). Then it starts a while(TRUE) loop. Within the loop, it runs socket_recvfrom(). I have it running 24/7 inside a screen window. I'm curious as to the cpu/memory/etc usage of a while(true) loop. The `top` command shows that the process is in the sbwait state (the OS is FreeBSD). I'm contemplating adding a usleep or even a sleep inside to loop. Would this be beneficial? I'm not too sure of how the internals of PHP work in terms of loops and such. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Is your socket blocking? If so, what's the timeout? while(true) { //wait for socket timeout } is the same as: while(true) { //read nothing from socket and sleep } Without the usleep(), the loop is going to loop as fast as your CPU will let it - meaning 100% CPU usage, all the time, at least in linux, although I'm pretty sure BSD would behave the same. As far as I'm aware, sockets in PHP behave almost identically to the way that they behave in C. I had an asynchronous TCP server written with the socket_* functions and noticed that the while(true) loop used 100% of the CPU because of the nonblocking sockets in use, but a usleep() solved that quite easily. Using blocking sockets with socket_select and a sane timeout relieved the high CPU usage as well. I believe it is blocking. Here's my socket_recvfrom: $Recv = socket_recvfrom($Socket, $Data, 512, MSG_WAITALL, $Name, $Port); So I think the the MSG_WAITALL is causing it to block until incoming data connection is closed (it never reaches the 512 byte mark before it echos the data). Here's the full script, minus the debugging/error catching stuff: $Socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); $Bind = socket_bind($Socket, '127.0.0.1', 1223); while(TRUE){ $Recv = socket_recvfrom($Socket, $Data, 512, MSG_WAITALL, $Name, $Port); print_r($Data); } As soon as the message is sent on the socket, it displays it. There's no delay until it builds up 512 bytes or anything. Also, I was playing around with ps and it looks like it's using 0% CPU, so I suppose it must be blocking. In the case that it is blocking, would it still be wise to throw a usleep in there just to be sure? Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of while(true) loop
On Wed, Sep 9, 2009 at 10:53 PM, APseudoUtopia apseudouto...@gmail.com wrote: On Wed, Sep 9, 2009 at 10:39 PM, Eddie Drapkinoorza...@gmail.com wrote: On Wed, Sep 9, 2009 at 10:32 PM, APseudoUtopia apseudouto...@gmail.com wrote: Hey list, I have a php cli script that listens on a UDP socket and, when data is sent to the socket, the script inserts it into a database. I'm using the real BSD socket functions, not fsock. The script runs socket_create(), then socket_bind(). Then it starts a while(TRUE) loop. Within the loop, it runs socket_recvfrom(). I have it running 24/7 inside a screen window. I'm curious as to the cpu/memory/etc usage of a while(true) loop. The `top` command shows that the process is in the sbwait state (the OS is FreeBSD). I'm contemplating adding a usleep or even a sleep inside to loop. Would this be beneficial? I'm not too sure of how the internals of PHP work in terms of loops and such. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Is your socket blocking? If so, what's the timeout? while(true) { //wait for socket timeout } is the same as: while(true) { //read nothing from socket and sleep } Without the usleep(), the loop is going to loop as fast as your CPU will let it - meaning 100% CPU usage, all the time, at least in linux, although I'm pretty sure BSD would behave the same. As far as I'm aware, sockets in PHP behave almost identically to the way that they behave in C. I had an asynchronous TCP server written with the socket_* functions and noticed that the while(true) loop used 100% of the CPU because of the nonblocking sockets in use, but a usleep() solved that quite easily. Using blocking sockets with socket_select and a sane timeout relieved the high CPU usage as well. I believe it is blocking. Here's my socket_recvfrom: $Recv = socket_recvfrom($Socket, $Data, 512, MSG_WAITALL, $Name, $Port); So I think the the MSG_WAITALL is causing it to block until incoming data connection is closed (it never reaches the 512 byte mark before it echos the data). Here's the full script, minus the debugging/error catching stuff: $Socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); $Bind = socket_bind($Socket, '127.0.0.1', 1223); while(TRUE){ $Recv = socket_recvfrom($Socket, $Data, 512, MSG_WAITALL, $Name, $Port); print_r($Data); } As soon as the message is sent on the socket, it displays it. There's no delay until it builds up 512 bytes or anything. Also, I was playing around with ps and it looks like it's using 0% CPU, so I suppose it must be blocking. In the case that it is blocking, would it still be wise to throw a usleep in there just to be sure? Thanks. MSG_WAITALL will block until 512 bytes of $Data has been received (or a disconnect), so unless you're receiving a ridiculous amount of data every iteration, forcing your CPU usage to be very high (which you've said isn't the case :P) then there's no real reason to sleep every while iteration. The reason why you're not getting a delay is because your clients are not maintaining an open connection to the socket, so it'll output as soon as the remote client disconnects from your server. I wouldn't necessarily say it's unwise or wise to sleep after every iteration, but it would depend on what kind of latency you need from your application, how much data it's receiving, etc. etc. Another thing you might want to consider about your design is that function, as you're using it, blocks until those 512 bytes have been read, so if a normal request (assuming a persistent connection) to your socket is 512 bytes, it could potentially sit there and wait indefinitely (not very likely). As it is, though, your server blocks (or sleeps, if you will) on the socket until a connection is made and it reads 512 bytes / the client disconnects, which seems to be doing well for your usage. The old adage if it ain't broke, don't fix it sort of applies here. Your program idles about at 0% CPU usage most of the time, for now. Until something changes, I'd leave it alone :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of while(true) loop
I have a php cli script that listens on a UDP socket and, when data is [8] So I think the the MSG_WAITALL is causing it to block until incoming data connection is closed (it never reaches the 512 byte mark before [8] your clients are not maintaining an open connection to the socket, so it'll output as soon as the remote client disconnects from your server. [8] if you will) on the socket until a connection is made and it reads 512 bytes / the client disconnects, which seems to be doing well for your usage. Sorry if I'm missing something obvious, but do the concepts of connection, close, and disconnect even apply in this case, since it's a UDP socket? Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php