[PHP] ext/mbstring compile time dependency
What does this mean in the PHP Change Log: Removed compile time dependency from ext/mbstring (Dmitry) Does it mean that mbstring is available by default in PHP 5.4? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
just yesterday i was reading through this wonderful and very funny presentation: http://talks.php.net/show/froscon08/0 for me it really drove home the message (among others) that it makes sense to find out where the real gains can be made before investing your efforts in optimization. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] FILTER_VALIDATE_INT - newbie question
On 10/7/09 6:04 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Wed, 2009-10-07 at 10:57 +0100, MEM wrote: Hello all, I'm having this strange behavior, and I do not understanding why... When I use FILTER_VALIDATE_INT I'm unable to get, on my input box, values starting with 0(zero), or values that are greater (in length) then 10 digits. I was expecting to be able to input the all range of integers. I've tried this: if (!filter_var($telefone, FILTER_VALIDATE_INT)) { $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.'; } And this: if (!filter_var($telefone, FILTER_VALIDATE_INT, array(options = array(min_range=-1, max_range=9 { $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.'; } And this: if (filter_var($telefone, FILTER_VALIDATE_INT, array(options = array(min_range=0, max_range=9))) == false ) { $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.'; } No success. :s What am I not getting? Thanks, Márcio Ps- Anyone knows where can we grab a good source information about FILTER_VALIDATE_INT specifically? Well, at a guess, if a number is 0, PHP see's that as equivalent to a false. Also, numbers over 10 digits may be going over the limit for your PHP install, assuming PHP actually attempts to convert the string to a real integer for the purpose of the filter. isn't a numeric string starting with 0 taken as octal? if so then 8 and 9 might cause validation errors. For things this simple, I've always tended to go with something like this: if(!preg_match('^[0-9 \+]$', $telefone)) { $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.'; } Which will check for all common types of phone numbers, including those where the user has put spaces in to separate groups of digits, and those that contain the + for country codes. right. phone numbers are not integers. people also often use parentheses, hyphens or dots in them. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Time Problem: always ten past xx
On 10/6/09 4:16 AM, Mert Oztekin mozte...@anadolusigorta.com.tr wrote: My mistake, I thought it was date() now strftime() Sorry (why do php developers create two different standarts for such similiar functions???☺ ) it's traditional to do so. it reminds me of the bit about subtly incompatible shells in unix from Real Programmers Don't Use Pascal: Even Unix might not be as bad on Real Programmers as it once was. The latest release of Unix has the potential of an operating system worthy of any Real Programmer-- two different and subtly incompatible user interfaces, an arcane and complicated teletype driver, virtual memory. If you ignore the fact that it's structured, even 'C' programming can be appreciated by the Real Programmer: after all, there's no type checking, variable names are seven (ten? eight?) characters long, and the added bonus of the Pointer data type is thrown in-- like having the best parts of Fortran and assembly language in one place. (Not to mention some of the more creative uses for #define.) we could collect a list: gnu make vs bsd make how many subtly different versions of grep are there? but i'm, sure it's been done already and i guess it's off topic. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [Fwd: [PHP] Sessions in databases]
On 10/6/09 10:26 AM, Il pinguino volante tuxs...@codeinside.it wrote: I have to realize an authentication system for a lot of users. I heard that someone uses to store session states (?) into a database. I'd like to know how and, expecially, WHY to do it and what's would be better (considering that I CANNOT -d'oh!- edit the php.ini file). i think you can modify the PHP session handler without touching php.ini: http://www.php.net/manual/en/function.session-set-save-handler.php i've read a lot on the web about this in recent weeks. different people offer their own justifications for the various approaches to session handling: PHP's file handler, user DB methods for the PHP session handler, PHP's memcache handler, zend session clustering, or do it yourself and don't use PHP sessions at all. there's a lot of controversy on the topic because different people have different requirements and preferences. so your question WHY? is quite complex. my motivation for considering user DB back-end to the PHP session handler was that it would replicate the session data over the DB cluster. retaining the PHP session front-end means less code rework and you keep its session locking. but it adds DB load, and the DB is often an app's bottleneck. whether or not that's ok depends on app specifics. i looked at memcache but i have two problems with it. one is that it is a cache system so it's not designed to be reliable: if it runs out of memory, restarts or crashes, the sessions are gone. the other is that the PHP session implementation is barely documented. i couldn't figure out how it implements the clustering (does it?) so i couldn't see how i would implement failover, recovery and maintenance procedures. http://phpslacker.com/2009/03/02/php-session-clustering-with-memcache/ one class i saw used memcached combined with DB in case of cache miss. it speeds up the reads but every write goes to both cache and DB. one thing that obviously helps is don't write the session to the DB if it hasn't changed. i'm not sure how best to do that yet. and you can optimize the writing of the session timestamp to the DB too. then there's the question of whether or not to use one DB connection for both session handling and the main app or use two connections. the latter is easier to code. row locking in the session table would be preferable to table locking. maybe we should work together on the code for all this? there's a webinar on zend platform session clustering that discusses various issues, bearing in mind it's a technical sales pitch. i don't think it's entirely fair to the DB methods. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: ternary operator sintax help
just as ashley said it. On 10/6/09 3:26 PM, MEM tal...@gmail.com wrote: Sorry all, It's ok. The sintax: ?php echo (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? Was right all the time. Anyway, I've learn something new: having a var with '' is not the same thing as not been unset. So we must pay attention on what cases we use isset, or !empty. Thanks a lot, Márcio -Original Message- From: João Cândido de Souza Neto [mailto:j...@consultorweb.cnt.br] Sent: terça-feira, 6 de Outubro de 2009 19:53 To: php-general@lists.php.net Subject: [PHP] Re: ternary operator sintax help ?= (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? MEM tal...@gmail.com escreveu na mensagem news:002401ca46b4$ed6ad6a0$c84083...@com... Hello all, I'm trying to display a div, only when some php value is set. Since this will be near html, I'd like to keep it on one line. So, I'd love to use shortcuts and a ternary operator for the effect. I'm having something like this right now, but the div still appears even if the error is NOT set. ?= (isset($erros['anexo'])) ? 'div class=mensagemErro' .$erros['anexo'].'/div' :''; ? :( Can I have your help with the right syntax ? Regards, The newbie on a Humpty Dumpty wall, Márcio -- 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] A really wacky design decision
On 10/4/09 6:36 AM, clanc...@cybec.com.au clanc...@cybec.com.au wrote: i might think it ok for (2260 == '226E1') to be true since php would be doing type juggling in a logical left-to-right manner: we start with an integer 2260, next is the juggling comparison operator, then a string, so it might reasonably try to convert the string to an integer and then compare. but with ('2260' == '226E1'), where both lhs and rhs are already of the same time, it seems elliptical, to say the least, that php should search the types to which it can convert the strings looking for one in which they are equal. The order doesn't matter; 2260 == 226e1, and 226e1==2260. in those two cases, all four operands are integer literals. no juggling is involved. and i would have expected the same for ('2260' == '226e1') and ('226e1' == '2260') since all operands are string literals and i'd be wrong. (evidently i'm not alone in making this mistake.) i get confused reading the manual: http://www.php.net/manual/en/language.types.type-juggling.php says that the context determines if the expression is converted. the example being the + operator. by definition, it's operands are numeric contexts so strings are converted. fair enough. now what about the == operator? http://www.php.net/manual/en/language.operators.comparison.php that page contradicts the previous one because it says that, when an operand is a string, the determination to convert an operand depends not on the context but on the specific data _of_ the operand. i think robert captured the essence of this confusion nicely with: On 10/3/09 1:53 PM, Robert Cummings rob...@interjinn.com wrote: Numeric strings are special :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
On 10/4/09 9:25 AM, MEM tal...@gmail.com wrote: Thanks a lot. To all. For the moment, I'm with the redirect solution that others have pointed. But after seen tedd example and watch Manuel videos, I'm starting to understand how the hidden field solution work as well. Well... I'm *starting* to understand I've not fully understand it yet, despite all your great examples. Because the structure of the code with hidden fields, seems quite different from the structure I have right now and I'm unable to make the switch. Here is the actual structure: if (isset($_POST['submit'])) { //declare variables $var = $_POST['var']; etc... //validate //process the form (send e-mail or save to database etc...) //redirect to success page. } else { Echo Sorry, couldn't process the form; } html form I suppose that the echo message telling we couldn't process the form does not appear when the form first loads, because the server side script is not requested on load, it is requested when the form submits to the php code presented on that same page (self). Tom Worster, is this precise? i don't think so. if the user requests the page a_form.php then the server will normally execute the a_form.php script regardless whether the form was submitted or not. to display a blank form, the user probably requests a_form.php with the GET method and probably without any GET parameters. the script will run but $_POST['submit'] is not set. so the script you show above will echo Sorry, couldn't process the form. that will likely confuse the user. in your structure you branch only two ways. i think you need three ways: 1 - the user simply arrived at the form. there is no POST data. the form was not submitted. 2 - there is POST data. the form was submitted. 2a - the POST data is unacceptable. 2b - the POST data is good. in branches 1 and 2a you send the form. in 2b, you send some other page or a redirect. in 1 you send the form blank. in 2a you might fill some form elements with data from POST and add some annotations to the form so the user knows what she or he did wrong. In the future, I will print tedd example, and Manuel scheme, and try to change the code above to accommodate hidden fields, because I still prefer having only one file. one can learn a lot reading other people's code. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class to generate Javascript Object ??
On 10/4/09 9:39 AM, Michael A. Peters mpet...@mac.com wrote: I wrote a php class to generate flowplayer/html5 media code for my site: http://www.shastaherps.org/xml_MMmediaClass.phps The buildFlashvars() function in it is really ugly and will be a pain to update as I modify the class in the future. What it does is generate a JavaScript object string, as described here: http://flowplayer.org/tools/flashembed.html I'm thinking (hoping) there is already a php class somewhere for generating JavaScript object strings that I can instead of my ugly easily breakable way of doing it. Anyone know of one? would json_encode() work for you... ? http://www.php.net/manual/en/function.json-encode.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
On 10/4/09 10:39 AM, MEM tal...@gmail.com wrote: i don't think so. if the user requests the page a_form.php then the server will normally execute the a_form.php script regardless whether the form was submitted or not. to display a blank form, the user probably requests a_form.php with the GET method and probably without any GET parameters. the script will run but $_POST['submit'] is not set. so the script you show above will echo Sorry, couldn't process the form. that will likely confuse the user. Ok... but please have a look here, I've uploaded and tested that code, and I can assure you that the message doesn't appear when the form first load: http://pastebin.com/m21078fe3 Note: if you use: copy to clipboard option the numbers will gone. this has a different structure from what you showed us in your email earlier today (Sunday, October 4, 2009 9:25 AM). this script has the structure: ?php $erros=array(); if(isset($_POST['submit'])) { ... if (!$erros) { ... // all done, now redirect: Redireciona(gracias.html); } else { echo (Sorry. The form couldn't be processed.); } } ? as i said before, a script will execute regardless. but this new script fragment does nothing except initialize $erros if $_POST['submit'] is not set (e.g. if the user requests the page without POSTing the form). i don't see a problem. this script also has the three cases i described clearly separated. now, what was your question? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
On 10/4/09 10:55 AM, tedd tedd.sperl...@gmail.com wrote: At 3:39 PM +0100 10/4/09, MEM wrote: i don't think so. if the user requests the page a_form.php then the server will normally execute the a_form.php script regardless whether the form was submitted or not. to display a blank form, the user probably requests a_form.php with the GET method and probably without any GET parameters. the script will run but $_POST['submit'] is not set. so the script you show above will echo Sorry, couldn't process the form. that will likely confuse the user. Ok... but please have a look here, I've uploaded and tested that code, and I can assure you that the message doesn't appear when the form first load: http://pastebin.com/m21078fe3 Note: if you use: copy to clipboard option the numbers will gone. Regards, Márcio The problem, as I see it, is that you are not willing to write a simple example and get that to work. Instead, you complicate things beyond your ability to understand. My advice, step back -- write a simple example that does what you want and then expand it. i agree that it does seem a bit as though Márcio is in such a hurry to make something work that the tasks of learning and understanding the fundamentals are being left aside. while that's maybe understandable, it's a bit frustrating when we're trying to explain the fundamentals. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
On 10/2/09 10:24 AM, tedd tedd.sperl...@gmail.com wrote: At 1:55 PM +0530 10/2/09, kranthi wrote: and yes i forgot to mention... i avoid hidden form elements because they can be modified very easily and hence pose a security threat. That depends upon how sloppy you are in coding. NONE of my hidden variables pose any security problems whatsoever. ...because one always assumes that data supplied in an http request is tainted. hence arguments about which exploit is more likely is rather pointless. a hidden input is really no different from any other form field. kranthi's argument would be consistent if he felt that all form inputs should be avoided because they are so easily modified as to pose a security threat. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
On 10/2/09 10:06 AM, MEM tal...@gmail.com wrote: I'm now understanding that even if the form is submitted to self, we can still use a redirect to a success_message_page.php. However, we must do this redirect, AFTER the form has submitted to himself. It's the only thing that we have to pay attention here, correct? Since we are not dealing with a confirmation page, or a multi-step form, the hidden field isn't necessary. It's this correct assumptions? the server script that runs in response to an http request for uri X can determine if conditions of success are met only after the server receives the request for X. so, if i understand your question, yes. i think your terminology is confusing you, e.g.: AFTER the form has submitted to himself. a form doesn't submit to itself. a form and a script that processes it are SEPARATE THINGS. it's better to think in terms of a user agent and a server communicating with http requests and responses. the UA sends http requests for uris X, Y, Z, etc. (with or without accompanying form data). the forms are part of html pages the server sends to the UA in http responses. a user drives the UA. PHP scripts are involved in the server's generation of responses. (a diagram might help.) now to your queston: if a UA has an html page that it got in a response for uri X; and if the page has a form; and if the form has no action attribute (or action=X); and if the user submits the form; then the UA will send the server an http request for X. next the server receives the request for X and the server runs a certain script, the php script you are coding. now i'm assuming these are your requirements: if that script determines failure, the user says at X and is asked to resubmit the form. if the script determines success, the user will wind up at a new uri: Y. further, you want to send the user over to Y by sending her UA an http response with Location=Y redirection. in these terms, the answer to your question should be pretty clear. your script has to receive and process requests for X before it can decide if it's going to respond to the UA with a Location=Y redirection or an html page with a form and an error message. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: A really wacky design decision
On 10/3/09 9:53 AM, Ralph Deffke ralph_def...@yahoo.de wrote: this is a clear sign that somebody is on a sin TRAIL, I would not even spend the time on what sin collections this guy got i see it more as ignorance than sin. to misunderstand the difference between $n++ and ++$n is a beginner error. as kr made very clear with their sequences of lessons in the original book, without actually saying so, becoming an experienced programming is like becoming a zen master. it is a progression to sophistication, the exemplars of which can be found here: http://www1.us.ioccc.org/years-spoiler.html i particularly recommend herrmann2 from 2001. masterful and dumbfounding. read the .hint file. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A really wacky design decision
On 10/3/09 7:21 AM, clanc...@cybec.com.au clanc...@cybec.com.au wrote: However there is one feature of PHP which, to my mind, is really bad design. How many of you can see anything wrong with the following procedure to search a list of names for a particular name? $i = 0; $j = count ($names); while ($i $j) { if ($names[$i] == $target) { break; } ++$i; } As long as the names are conventional names, this procedure is probably safe to use. However if you allow the names to be general alphanumeric strings, it is not reliable. One of my programs recently broke down in one particular case, and when I eventually isolated the bug I discovered that it was matching '2260' to '226E1'. (The logic of this is: 226E1 = 226*10^1 = 2260). I agree that I was well aware of this trap, and that I should not have used a simple comparison, but it seems to me to be a bizarre design decision to assume that anything which can be converted to an integer, using any of the available notations, is in fact an integer, rather than making the default to simply treat it as a string. this is odd. i might think it ok for (2260 == '226E1') to be true since php would be doing type juggling in a logical left-to-right manner: we start with an integer 2260, next is the juggling comparison operator, then a string, so it might reasonably try to convert the string to an integer and then compare. but with ('2260' == '226E1'), where both lhs and rhs are already of the same time, it seems elliptical, to say the least, that php should search the types to which it can convert the strings looking for one in which they are equal. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A really wacky design decision
On 10/3/09 12:25 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Sat, 2009-10-03 at 11:57 -0400, Tom Worster wrote: On 10/3/09 7:21 AM, clanc...@cybec.com.au clanc...@cybec.com.au wrote: However there is one feature of PHP which, to my mind, is really bad design. How many of you can see anything wrong with the following procedure to search a list of names for a particular name? $i = 0; $j = count ($names); while ($i $j) { if ($names[$i] == $target) { break; } ++$i; } As long as the names are conventional names, this procedure is probably safe to use. However if you allow the names to be general alphanumeric strings, it is not reliable. One of my programs recently broke down in one particular case, and when I eventually isolated the bug I discovered that it was matching '2260' to '226E1'. (The logic of this is: 226E1 = 226*10^1 = 2260). I agree that I was well aware of this trap, and that I should not have used a simple comparison, but it seems to me to be a bizarre design decision to assume that anything which can be converted to an integer, using any of the available notations, is in fact an integer, rather than making the default to simply treat it as a string. this is odd. i might think it ok for (2260 == '226E1') to be true since php would be doing type juggling in a logical left-to-right manner: we start with an integer 2260, next is the juggling comparison operator, then a string, so it might reasonably try to convert the string to an integer and then compare. but with ('2260' == '226E1'), where both lhs and rhs are already of the same time, it seems elliptical, to say the least, that php should search the types to which it can convert the strings looking for one in which they are equal. I don't know what you mean by elliptical, but I'd expect and certainly hope that PHP wouldn't try to convert both strings to something which would mean they had the same value. Also, afaik, if the variables types are exactly the same, PHP won't try to convert either of them for a comparison i once had such hope too. $ php -r var_dump('2260' == '226E1'); bool(true) elliptical: tending to be ambiguous, cryptic, or obscure: an elliptical prose that is difficult to translate. (http://dictionary.reference.com/browse/elliptical) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
On 10/1/09 8:00 AM, MEM tal...@gmail.com wrote: One last question about this: I've done a self submit form, after hearing all the advantages expressed here. But how could we relate, without using javascript, a self submit form with a success page or a confirmation page that doesn't show the form? Can please someone throw me some infos about this please? i use one php script that knows how to deliver more than one html page depending on the outcome of processing of form input and the rest. i'm sure there are other ways. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Self-Process php forms or not?
On 10/1/09 10:13 AM, tedd tedd.sperl...@gmail.com wrote: At 1:00 PM +0100 10/1/09, MEM wrote: One last question about this: I've done a self submit form, after hearing all the advantages expressed here. But how could we relate, without using javascript, a self submit form with a success page or a confirmation page that doesn't show the form? Can please someone throw me some infos about this please? MEM: Here's what I do -- it's pretty simple. I use a hidden input variable I call step and monitor it as the user clicks whatever form submit they are on -- it works like so: $step = isset($_POST['step']) ? $_POST['step'] : 0; switch ($step) { case 0: // present the first form to the user // collect data // you can enhance the user experience by using javascript here. // input type=hidden name=step value=1 break; case 1: // present second form to the user // clean data // if data OK then record data in db input type=hidden name=step value=2 // if data not OK then send user back input type=hidden name=step value=0 break; case 2: //present the third form to the user // success, or confirmation, or thank you page break; } Now, to make things easier for the user, be sure to set session variables for all the data collected in the first form so that IF you send the user back to the first form, the user doesn't have to reenter everything. i do pretty much the same thing. each form in my html template files has a form name tucked away in a hidden input element. the only difference from your method is that the names are unique across the application. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] intl extension on os x
On 9/28/09 2:41 AM, Tommy Pham tommy...@yahoo.com wrote: - Original Message From: Tom Worster f...@thefsb.org To: PHP General List php-general@lists.php.net Sent: Sunday, September 27, 2009 5:34:45 PM Subject: [PHP] intl extension on os x does anyone know how to install intl on os x 10.5? it seems a libicu binary is included in os x but not with headers. fink has a package for installing the headers. maybe that would allow pecl to install the intl extension. has anyone done this successfully? or know any other way to get intl running on 10.5? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php When Apple made the big change of OS a few years back, they switch to *BSD based OS, with the GUI from NeXT, which Apple bought. You should be able to compile most linux/unix codes on Mac though. Have you looked at Apple's developer's resources/documentation? yes indeed. often you can successfully compile and install on os x things that run on freebsd or linux. but port configuration is often substantially different and not entirely handled by autoconf. (even compiling php requires some tricks.) in these cases i refer to google because people smarter than me (one assumes, everything you read on the internet being true, of course) often blog their recipe if the find one. but i found nothing for this problem. that's why i asked here. at this stage, i installed the fink package libicu36-dev-3.6.0-5, supposedly libicu headers and it seems to have done something, i'm not entirely sure exactly what. and i'm not convinced that the headers are for the same libicu version that's in /usr/lib. but somehow, though i'm not clear how one configures pecl source, i managed to get pecl to compile and install the extension. anyway, in the cli the command collator_create( 'en_US' ); did not provoke an error, so maybe that works. but if i add extension=intl.so to php.ini and restart apache, php says: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20060613/intl.so' so we're not done yet. if i get it done, maybe i'll blog my recipe. freebsd, otoh, has a port for pecl-intl so it was trivial to install. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: session.gc_maxlifetime
it could be ip address changes. interesting thought. i think i should add some special logging. it's a dedicated freebsd server with one app. On 9/23/09 6:43 PM, Ralph Deffke ralph_def...@yahoo.de wrote: finaly we went with a custom cooky handling, however the customers requirements where two days. if u are shure that the server is still the same hardware like it has been 6 years ago then it might be some client stuff, however if there are other applications, pages running (virtual servers) then it would still be to consider. mamory and resource management is deep os. again I wouldn't trust for that amount of session livetime. I dont think, putting it down to three hours would help much. and of course, it could be client side also. Can't you figure out the clients? and keep in mind that a lot of people connect to UMTS rigzt now, these systems deconnect on idle lines and reconect without the users even know it. Also a lot of lines change IP address at midnihgt. cheers ralph_def...@yahoo.de Tom Worster f...@thefsb.org wrote in message news:c6e00521.12d98%...@thefsb.org... there's a need for long timeouts in this app but could perhaps be reduced from 6 to 3 hours. the sessions are cookie based using php's 'file' handler and session.cookie_lifetime=0. the server appears to have plenty of free memory and appears not to have swapped in nearly a year of uptime. load averages indicate a pretty quiet server. there are currently 170 kbyte total in 90 serialized session files which is typical and not a memory load. the distribution of modification times doesn't indicate heavy activity: ~20 files in the last 15 minutes and 35 in the last hour. so i think the os can handle this. plus the app ran for 6 years before anyone reported being prematurely logged off. i'm looking for other possibilities: odd browser behavior, network trouble, ... are there any browsers that have configurable cookie handling policy such that they time out a cookie? one web site i use displays this curious message: For your protection, sessions are open for a limited period of time on our website. Please sign-on again. NOTE: Your browser may also limit secure connection time, and automatically log you out independent of our timeout procedure. that could be referring to browsers timing out an ssl connection. or perhaps the cookie? btw: when you said in your email you wouldn't trust a long gc_maxlifetime, and you would only use a cookie-based solution for long session. did you mean that you wouldn't trust php's cookie-based session handler? and you would use a custom handler instead? On 9/22/09 4:46 PM, Ralph Deffke ralph_def...@yahoo.de wrote: Hi Tom, in sometimes 2001 I did have incidences with those things, and as I remember over the past years there where some trouble with operating systems and stuff. This part is very deep inside the os. I would expect that this is still to consider. I also would check, if this occurs on very busy/low memory server. If I would programm the garbage collection clean up part, and if the server is about to run out of memory, I would kill sessions being longer time idle even when they are not yet as old as it is set in the gc_maxlifetime. This would be far better then shutting down the whole server just because there a 100 of idle sessions waiting to get used again. as u mention a maxlivetime of 6h I would bet, that this is the problem. I would not trust such a long lifetime at all. If sessions have to be active such a long time, I would see only cooky based solutions let me know, what u did investigate on this. ralph_def...@yahoo.de Tom Worster f...@thefsb.org wrote in message news:c6deae55.12cae%...@thefsb.org... thank you, Ralph! i'm going to be bold and assume that tom at punkave dot com is right despite that the report was discarded. i got a complaint from a client about some users reporting being logged out with rather short periods of inactivity. but session.gc_maxlifetime is set to 6 hours so i don't think that's the source of the problem. On 9/22/09 4:17 PM, Ralph Deffke ralph_def...@yahoo.de wrote: Hi Tom, i did find this in the bug reports, its pretty new and should be an answer. http://news.php.net/php.doc.bugs/2653 ralph_def...@yahoo.de Tom Worster f...@thefsb.org wrote in message news:c6de9eee.12c8d%...@thefsb.org... i'm not 100% sure what the manual means when it says... session.gc_maxlifetime integer session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and cleaned up. Garbage collection occurs during session start. what event exactly does the after which here refer to? i'd like to think that it means that a session is eligible for gc no sooner than session.gc_maxlifetime seconds after the most recent access (read or write) to that session. but it seems dangerously presumptuous
[PHP] catch an iconv E_NOTICE
i have this hack that works up to a point... function my_err_handler($errno, $errstr, $errfile, $errline) { if ( preg_match('/iconv/', $errstr) ) { throw new Exception('iconv error'); } else { // ? how to invoke default error handler ? } } set_error_handler(my_err_handler, E_NOTICE); try { $s = iconv($enc1, $enc2, $s); } catch (Exception $e) { // deal with the failed conversion } but i'd like proceed with default error handling in the branch with the question marks. how can i do that? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] catch an iconv E_NOTICE
On 9/24/09 10:30 AM, David Otton phpm...@jawbone.freeserve.co.uk wrote: 2009/9/24 Tom Worster f...@thefsb.org: but i'd like proceed with default error handling in the branch with the question marks. how can i do that? An error handler that passes through to the previous error handler: ?php error_reporting(E_ALL); function my_error_handler($errno, $errstr, $errfile, $errline) { restore_error_handler(); trigger_error($errstr, $errno); } set_error_handler('my_error_handler', E_ALL); trigger_error('TEST', E_USER_ERROR); You'll lose the file and line, though, because you're actually raising another error with the same message at a new point in the code. and i'd need to set my error handler back again to catch the next iconv error: function my_err_handler($errno, $errstr, $errfile, $errline) { if ( preg_match('/iconv/', $errstr) ) { throw new Exception('iconv error'); } else { restore_error_handler(); trigger_error($errstr, $errno); set_error_handler('my_error_handler', E_ALL); } } set_error_handler('my_error_handler', E_ALL); not lovely. as it stands, my own code writes the error message to the log file in that place. i'm not sure this is an improvement. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: session.gc_maxlifetime
there's a need for long timeouts in this app but could perhaps be reduced from 6 to 3 hours. the sessions are cookie based using php's 'file' handler and session.cookie_lifetime=0. the server appears to have plenty of free memory and appears not to have swapped in nearly a year of uptime. load averages indicate a pretty quiet server. there are currently 170 kbyte total in 90 serialized session files which is typical and not a memory load. the distribution of modification times doesn't indicate heavy activity: ~20 files in the last 15 minutes and 35 in the last hour. so i think the os can handle this. plus the app ran for 6 years before anyone reported being prematurely logged off. i'm looking for other possibilities: odd browser behavior, network trouble, ... are there any browsers that have configurable cookie handling policy such that they time out a cookie? one web site i use displays this curious message: For your protection, sessions are open for a limited period of time on our website. Please sign-on again. NOTE: Your browser may also limit secure connection time, and automatically log you out independent of our timeout procedure. that could be referring to browsers timing out an ssl connection. or perhaps the cookie? btw: when you said in your email you wouldn't trust a long gc_maxlifetime, and you would only use a cookie-based solution for long session. did you mean that you wouldn't trust php's cookie-based session handler? and you would use a custom handler instead? On 9/22/09 4:46 PM, Ralph Deffke ralph_def...@yahoo.de wrote: Hi Tom, in sometimes 2001 I did have incidences with those things, and as I remember over the past years there where some trouble with operating systems and stuff. This part is very deep inside the os. I would expect that this is still to consider. I also would check, if this occurs on very busy/low memory server. If I would programm the garbage collection clean up part, and if the server is about to run out of memory, I would kill sessions being longer time idle even when they are not yet as old as it is set in the gc_maxlifetime. This would be far better then shutting down the whole server just because there a 100 of idle sessions waiting to get used again. as u mention a maxlivetime of 6h I would bet, that this is the problem. I would not trust such a long lifetime at all. If sessions have to be active such a long time, I would see only cooky based solutions let me know, what u did investigate on this. ralph_def...@yahoo.de Tom Worster f...@thefsb.org wrote in message news:c6deae55.12cae%...@thefsb.org... thank you, Ralph! i'm going to be bold and assume that tom at punkave dot com is right despite that the report was discarded. i got a complaint from a client about some users reporting being logged out with rather short periods of inactivity. but session.gc_maxlifetime is set to 6 hours so i don't think that's the source of the problem. On 9/22/09 4:17 PM, Ralph Deffke ralph_def...@yahoo.de wrote: Hi Tom, i did find this in the bug reports, its pretty new and should be an answer. http://news.php.net/php.doc.bugs/2653 ralph_def...@yahoo.de Tom Worster f...@thefsb.org wrote in message news:c6de9eee.12c8d%...@thefsb.org... i'm not 100% sure what the manual means when it says... session.gc_maxlifetime integer session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and cleaned up. Garbage collection occurs during session start. what event exactly does the after which here refer to? i'd like to think that it means that a session is eligible for gc no sooner than session.gc_maxlifetime seconds after the most recent access (read or write) to that session. but it seems dangerously presumptuous to assume that this is the case. what do you take it to mean? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] session.gc_maxlifetime
i'm not 100% sure what the manual means when it says... session.gc_maxlifetime integer session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and cleaned up. Garbage collection occurs during session start. what event exactly does the after which here refer to? i'd like to think that it means that a session is eligible for gc no sooner than session.gc_maxlifetime seconds after the most recent access (read or write) to that session. but it seems dangerously presumptuous to assume that this is the case. what do you take it to mean? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: session.gc_maxlifetime
thank you, Ralph! i'm going to be bold and assume that tom at punkave dot com is right despite that the report was discarded. i got a complaint from a client about some users reporting being logged out with rather short periods of inactivity. but session.gc_maxlifetime is set to 6 hours so i don't think that's the source of the problem. On 9/22/09 4:17 PM, Ralph Deffke ralph_def...@yahoo.de wrote: Hi Tom, i did find this in the bug reports, its pretty new and should be an answer. http://news.php.net/php.doc.bugs/2653 ralph_def...@yahoo.de Tom Worster f...@thefsb.org wrote in message news:c6de9eee.12c8d%...@thefsb.org... i'm not 100% sure what the manual means when it says... session.gc_maxlifetime integer session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and cleaned up. Garbage collection occurs during session start. what event exactly does the after which here refer to? i'd like to think that it means that a session is eligible for gc no sooner than session.gc_maxlifetime seconds after the most recent access (read or write) to that session. but it seems dangerously presumptuous to assume that this is the case. what do you take it to mean? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] moving to quad core
On 9/15/09 10:54 AM, Andres Gonzalez and...@packetstorm.com wrote: I have an application developed that uses alot of PHP. Currently, it is running on a Ubuntu 8.04 , single core CPU host. We are moving to a quad core host for this application. Is there anything special that I need to do to configure PHP to run on a quad core host? I noticed that my current single core system has PHP configured with Thread Safety disabled (as reported from phpinfo()). Does that need to be enabled to run in a multi-core environment? Any other suggestions for configuring PHP for multi-core use? interesting question. i never paid any attention to the possibility of needing to make config changes when moving from single to multi-core computers. i'm using apxs2 and just assumed that there's no threading within each httpd process. in other words, i assumed it's up to the os' scheduler to make something of the hardware. i'm curious to hear more on the topic. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] server name that the user agent used
On 9/13/09 10:24 PM, Tommy Pham tommy...@yahoo.com wrote: --- On Sun, 9/13/09, Tom Worster f...@thefsb.org wrote: From: Tom Worster f...@thefsb.org Subject: [PHP] server name that the user agent used To: PHP General List php-general@lists.php.net Date: Sunday, September 13, 2009, 8:21 PM when using apache with one vhost that responds to a few different hostnames, e.g. domain.org, y.domain.org, x.domain.org, let's say the vhost's server name is y.domain.org and the other two are aliases, is there a way in php to know which of these was used by the user agent to address the server? Did you see what comes up with php_info() for $_SERVER[SERVER_NAME] or $_SERVER[HTTP_HOST] ? SERVER_NAME returns whatever apache has as the vhost's configured server name. the php manual says of HTTP_HOST: Contents of the Host: header from the current request, if there is one. in which the last 4 words are a little off-putting. but: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23 i much more encouraging. the field is mandatory and should have what i'm looking for. it's absence is cause for a 400. casual testing (with a modern non-ie browser) seems to bear this out. so i'll try using that with fallback to my current techniques if i don't find a good value in HTTP_HOST. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] APC - Upload progress problem. apc
On 9/14/09 5:39 AM, Phred White phpl...@planetphred.com wrote: On Sep 13, 2009, at 8:50 PM, Eddie Drapkin wrote: On Sun, Sep 13, 2009 at 9:38 PM, Phred White phpl...@planetphred.com wrote: On Sep 13, 2009, at 7:34 PM, Eddie Drapkin wrote: On Sun, Sep 13, 2009 at 8:29 PM, Phred White phpl...@planetphred.com wrote: On Sep 11, 2009, at 1:17 PM, Eddie Drapkin wrote: On Fri, Sep 11, 2009 at 1:02 PM, Phred White phpl...@planetphred.com wrote: Hey folks.. Anybody ever use APC to show upload progress? It sounds really cool, but apc_fetch always returns false a value for uploads. I can apc_add something and fetch it, but not for uploads : ( (set-up: php-apc 3.0.19, Apache2, php 5.2.10, no suhosin patch) There is little info to google on this, and I've been through it. I was hoping some hard core, tireless, php programmer just knew the answer. With high anxiety, Phred I recently had to do roughly the same thing (visual upload progress) and I had done some research into APC. What I learned was that the upload tracking didn't work with FastCGI (which would have prevented our switch to nginx, but not a deal breaker) and what broke the deal, though, was the fact that APC's upload progress is apparently not thread safe, so if person A is uploading a file and person B starts an upload, you get a silent failure. Which brings me to another point, it seems to silently fail. Ultimately, I went with a flash based solution because the APC solution had way too many problems to be really useful. It's a nice thought, but I wouldn't recommend it. I know this isn't exactly what you wanted, but I had a similar experience and thought I would share :) Dang! You are exactly right - that isn't what I wanted to hear! : ( But better to know now, then when my timeline is already used up. Did you write your own flash based solution, or use an canned one? Thanks, Phred I actually wound up using swfupload because of a friend's recommendation and also because there's a nifty jQuery plugin for it. The project's main site: http://swfupload.org The jQuery plugin I'm using: http://blogs.bigfish.tv/adam/2009/06/14/swfupload-jquery-plugin/ The *only* issue I could find with a flash based uploader (I don't regard flash installation as an issue because we're a video based site and well, if you're using our site to watch videos...) was there's an as-of-yet unresolved bug in linux flash clients that locks a browser until upload is completed. Adobe's bug tracker seems to be down for me at the moment, but if you really want the bug, let me know offlist and I'll supply it later. :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hey Eddie: One more question... I have an existing form that provides other data that need to be linked to the file upload. It looks like swfupload, just uploads all by its lonesome. I also need the javascript form validator to be triggered before any uploading occurs. Is this possible? You don't have to tell me how (though I wouldn't mind a few clues). I just want to know if it will meet my needs once i dig in. Thanks That should all be possible. I'd take a look at http://demo.swfupload.org/v220/featuresdemo/index.php as that has most of that happening on the page and you can bootleg some of their example code :) Bummer... It looked so promising, but on Macs, Flash has to load the entire file into memory to upload! R. So, it isn't viable for big files (Gig +) if you need it to be cross platform. So now I am looking at perl of all things! If you have any ideas let me know. thanks for all your help so far. with files that big, perhaps could write client js that polls a script on the server that simply returns the file size(s)? if you want a thermometer, use the number to resize a colored div. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] server name that the user agent used
On 9/14/09 9:03 AM, Tom Worster f...@thefsb.org wrote: On 9/13/09 10:24 PM, Tommy Pham tommy...@yahoo.com wrote: --- On Sun, 9/13/09, Tom Worster f...@thefsb.org wrote: From: Tom Worster f...@thefsb.org Subject: [PHP] server name that the user agent used To: PHP General List php-general@lists.php.net Date: Sunday, September 13, 2009, 8:21 PM when using apache with one vhost that responds to a few different hostnames, e.g. domain.org, y.domain.org, x.domain.org, let's say the vhost's server name is y.domain.org and the other two are aliases, is there a way in php to know which of these was used by the user agent to address the server? Did you see what comes up with php_info() for $_SERVER[SERVER_NAME] or $_SERVER[HTTP_HOST] ? SERVER_NAME returns whatever apache has as the vhost's configured server name. the php manual says of HTTP_HOST: Contents of the Host: header from the current request, if there is one. in which the last 4 words are a little off-putting. but: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23 i much more encouraging. the field is mandatory and should have what i'm looking for. it's absence is cause for a 400. casual testing (with a modern non-ie browser) seems to bear this out. so i'll try using that with fallback to my current techniques if i don't find a good value in HTTP_HOST. extra info: the Host: header isn't in HTTP/1.0, hence those off-putting 4 words, i guess. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] server name that the user agent used
On 9/14/09 2:11 PM, Lars Torben Wilson tor...@php.net wrote: Tom Worster wrote: On 9/13/09 10:24 PM, Tommy Pham tommy...@yahoo.com wrote: --- On Sun, 9/13/09, Tom Worster f...@thefsb.org wrote: From: Tom Worster f...@thefsb.org Subject: [PHP] server name that the user agent used To: PHP General List php-general@lists.php.net Date: Sunday, September 13, 2009, 8:21 PM when using apache with one vhost that responds to a few different hostnames, e.g. domain.org, y.domain.org, x.domain.org, let's say the vhost's server name is y.domain.org and the other two are aliases, is there a way in php to know which of these was used by the user agent to address the server? Did you see what comes up with php_info() for $_SERVER[SERVER_NAME] or $_SERVER[HTTP_HOST] ? SERVER_NAME returns whatever apache has as the vhost's configured server name. the php manual says of HTTP_HOST: Contents of the Host: header from the current request, if there is one. in which the last 4 words are a little off-putting. but: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23 i much more encouraging. the field is mandatory and should have what i'm looking for. it's absence is cause for a 400. casual testing (with a modern non-ie browser) seems to bear this out. so i'll try using that with fallback to my current techniques if i don't find a good value in HTTP_HOST. The reason that it might not be available is that PHP is not always running in a web context. $_SERVER['HOST_NAME'] would have no meaning, for instance, in the CLI SAPI. However, if running under a web SAPI, and if the web server provides the info, PHP will pass it on to its scripts. and, for the record, in the web environment there's cause for caution using either HTTP_HOST or, if UseCanonicalName is off or you can't be sure of its value, SERVER_NAME: http://shiflett.org/blog/2006/mar/server-name-versus-http-host in my current app, i should be able to match for acceptable values and fall back to defaults on failure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] server name that the user agent used
when using apache with one vhost that responds to a few different hostnames, e.g. domain.org, y.domain.org, x.domain.org, let's say the vhost's server name is y.domain.org and the other two are aliases, is there a way in php to know which of these was used by the user agent to address the server? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] get an object property
On 9/13/09 3:21 AM, Lars Torben Wilson tor...@php.net wrote: On 9/12/09 9:50 AM, Tom Worster f...@thefsb.org wrote: but let me give you a more different example: $a and $b are normally both objects, each with various members including a prop q, but sometimes $a is false. i want the q of $a if $a isn't false, otherwise that of $b. ($a ? $a : $b)-q // is not php, afaik before you suggest one, i know there are simple workarounds. You're right, that isn't PHP syntax. One workaround that came to mind which does a similar thing (although using a different mechanism) is this: ${$a ? 'a' : 'b'}-q i would not have thought of that. interesting... and while i'm at it, and using my original error, how come... function o() { return (object) array('q'=7); } echo o()-q; // is ok syntax, but function a() { return array('q'=5); } echo a()['q']; // isn't? I'm afraid I can't answer that right now--it does perhaps seem inconsistent at first glance, although I can't say I've ever missed it or felt that using syntax like that would make my life any better. Maybe it would. Then again, I can also see an argument being made for allowing the object syntax but not the array syntax: in the case of objects, you can have a clean class declaration which is pretty much self-documenting, and later users of the class can have a clear idea of which properties are available and which are not, and they can thus be sure that o()-q will not result in uninitialized property problems. Using the array syntax you could never be sure that the index requested actually exists. Of course, this holds true only for people like me who don't really like the idea of creating objects on the fly in PHP unless there's a very good reason to. Usually in PHP such tasks are better handled by arrays anyway. the dbms abstraction library i use delivers rows, by default, as objects. so i commonly handle dynamically generated data in the form of objects, though it's not my code generating those objects. i think that's one reasons why i often find i would use objects as data structures. and because i find the dynamic objects in js convenient. but i think you're preference reflects more closely was probably the concept of php's version of oop: an object is an instances of a static class. in any case, now that i've confirmed that i'm not merely unaware of the features i was hunting for, and that they don't exist by design, i can perhaps move on. on a related note, way back when xml was ascendant as the most exciting new technology to hit the net since java, i was not impressed. what a horrid syntax for specifying and communicating data, i would argue. why not use the syntax from some sensible programming language instead? js, for example? easy to parse, less overhead, human readable (i find xml hard to read), etc. then eventually json happened, without all the hype and fanfare, just doing the job very conveniently. i love it. and to make that comment vaguely php related, i now use json to encode structured data that i want to write to the php error log. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] get an object property
On 9/12/09 12:31 AM, Paul M Foster pa...@quillandmouse.com wrote: On Fri, Sep 11, 2009 at 07:31:01PM -0400, Tom Worster wrote: if i have an expression that evaluates to an object, the return value from a function, say, and i only want the value of one of the objects properties, is there a tidy way to get it without setting another variable? to illustrate, here's something that doesn't work, but it would be convenient if it did: $o = array( (object) array('a'=1), (object) array('a'=2) ); if ( end($o)-a 1 ) { // can't use - like this! ... } You should use print_r() or var_dump() to investigate what happens when you try to cast an array into an object. I myself don't know what would happen. Also, what's allowed and what effects are produced could depend heavily on the version of PHP you're running. Version 4 != 5 != 5.3 in this respect. i did that long ago when i was looking for php's object literal syntax. i didn't find one. we discussed it here more recently and consensus appeared to be that casting an array was the most convenient workaround. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] get an object property
On 9/12/09 1:32 AM, Lars Torben Wilson tor...@php.net wrote: Tom Worster wrote: if i have an expression that evaluates to an object, the return value from a function, say, and i only want the value of one of the objects properties, is there a tidy way to get it without setting another variable? to illustrate, here's something that doesn't work, but it would be convenient if it did: $o = array( (object) array('a'=1), (object) array('a'=2) ); if ( end($o)-a 1 ) { // can't use - like this! ... } What version of PHP are you using? Your example should work. Torben 5.2.9. what version does it work in? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] get an object property
On 9/12/09 9:50 AM, Tom Worster f...@thefsb.org wrote: On 9/12/09 1:32 AM, Lars Torben Wilson tor...@php.net wrote: Tom Worster wrote: if i have an expression that evaluates to an object, the return value from a function, say, and i only want the value of one of the objects properties, is there a tidy way to get it without setting another variable? to illustrate, here's something that doesn't work, but it would be convenient if it did: $o = array( (object) array('a'=1), (object) array('a'=2) ); if ( end($o)-a 1 ) { // can't use - like this! ... } What version of PHP are you using? Your example should work. Torben 5.2.9. what version does it work in? i shamefully beg your pardon, lars. i was sure i tested the example but it's clear to me now i either didn't or i made a mistake. end($o)-a IS php syntax! so - may follow a function (or method, i guess) call. but let me give you a more different example: $a and $b are normally both objects, each with various members including a prop q, but sometimes $a is false. i want the q of $a if $a isn't false, otherwise that of $b. ($a ? $a : $b)-q // is not php, afaik before you suggest one, i know there are simple workarounds. but mine is a theoretical question about syntax, not a practical one. i'm exploring php's syntactic constraints on the - operator in contrast to, say, the + or . operators. and in contrast to other languages. for example, the . in js seems more generally allowed than - (or, for that matter, []) in php. programmers (especially using jquery) are familiar with using . after an expression that evaluates to an object, e.g. body p id=thepara class=top x23 indentMy x class number is span id=num/span/p div id=mandatory style=border: solid red 1px/div script type=text/javascript document.getElementById('num').innerText = ( ( document.getElementById('optional') || document.getElementById('mandatory') ).appendChild(document.getElementById('thepara')) .className.match(/x(\d+)/) || [0,'absent'] )[1] /script /body which shows . after objects, method calls and expressions (as well as the [] operator applied to an expression). do we just live without in phpville or am i missing something? and while i'm at it, and using my original error, how come... function o() { return (object) array('q'=7); } echo o()-q; // is ok syntax, but function a() { return array('q'=5); } echo a()['q']; // isn't? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] get an object property
if i have an expression that evaluates to an object, the return value from a function, say, and i only want the value of one of the objects properties, is there a tidy way to get it without setting another variable? to illustrate, here's something that doesn't work, but it would be convenient if it did: $o = array( (object) array('a'=1), (object) array('a'=2) ); if ( end($o)-a 1 ) { // can't use - like this! ... } -- 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] 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] 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
[PHP] mysql user session handler
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
Re: [PHP] mysql user session handler
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
Re: [PHP] Re: Best way to test for form submission?
On 8/29/09 9:29 AM, tedd tedd.sperl...@gmail.com wrote: At 1:18 AM -0700 8/29/09, Warren Vail wrote: To test a form I usually send the form contents to a php file that contains the following; foreach($_POST as $nm = $val) echo _POST[.$nm.] [.$val.]br; foreach($_GET as $nm = $val) echo _GET[.$nm.] [.$val.]br; Checkboxes and radio buttons only send their value if the control is checked. That's correct, here's the way I solve both types: http://php1.net/b/form-radio http://php1.net/b/form-radio1 http://php1.net/b/form-checkbox/ http://php1.net/b/form-checkbox1/ warren's test script above doesn't work so well with tedd's scheme for naming radios checkboxs. tedd uses name=option[] in the markup so in warren's script, when $nm is 'option', $val will be an array so it won't convert to a string in .$val.. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: unset() something that doesn't exist
On 8/25/09 5:01 AM, Stuart stut...@gmail.com wrote: 2009/8/25 Ralph Deffke ralph_def...@yahoo.de: causes an error Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'$'' in C:\wamp\www\TinyCreator\testCrapp6.php on line 42 This is a syntax error, not a runtime error. You've clearly done something wrong. Tom Worster f...@thefsb.org wrote in message news:c6b87877.11463%...@thefsb.org... is it the case that unset() does not trigger an error or throw an exception if it's argument was never set? Absolutely. -Stuart thank you, stuart. in the interest of wrapping up the archive of this thread on topic, may i summarize? in a statement like: unset($something); if $something is not set, i.e. isset($something) would, in the same context, evaluate to false, the statement WILL NOT trigger an error at any level or throw an exception. the reason i ask is this: sometimes it's important to unset a variable at a position in a script where as programmer i don't know if the variable is set or not. session variables are good examples. i sure don't what reports of such unsets in my php error logs. but i also don't want to do: if (isset($something)) unset($something); if i don't need to. and the answer is: i don't. tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Why aren't you rich? (was Re: unset() something that doesn't exist)
On 8/26/09 10:08 AM, tedd tedd.sperl...@gmail.com wrote: I had a client say to me once If you're so smart, then why aren't you rich? how about: i'm smart enough that i know not to waste my allotted time on this planet amassing riches. i know plenty of rich people, many of whom earned their wealth. i envy the financial security but little else of that their wealth has done to their lives. time is really what i want more of. some wealthy trust fund types have wealth and time but they have other problems i'm glad i don't. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: unset() something that doesn't exist
On 8/25/09 5:00 AM, Ralph Deffke ralph_def...@yahoo.de wrote: of course its a syntax error, because unset() IS NOT A FUNCTION its a language construct that's hard to believe. i can't imagine how the compiler could reliably predict if the argument will be set or not when the unset line is executed. Stuart stut...@gmail.com wrote in message news:a5f019de0908250201g14e4b61cn73c6cd67da6f...@mail.gmail.com... 2009/8/25 Ralph Deffke ralph_def...@yahoo.de: causes an error Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'$'' in C:\wamp\www\TinyCreator\testCrapp6.php on line 42 This is a syntax error, not a runtime error. You've clearly done something wrong. Tom Worster f...@thefsb.org wrote in message news:c6b87877.11463%...@thefsb.org... is it the case that unset() does not trigger an error or throw an exception if it's argument was never set? Absolutely. -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] unset() something that doesn't exist
is it the case that unset() does not trigger an error or throw an exception if it's argument was never set? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to make sure that the target file to read is not under writing by others?
On 8/19/09 9:56 PM, Clancy clanc...@cybec.com.au wrote: I gather from this discussion that PHP allows two users to open a file for R/W? I had assumed it wouldn't. i think php does allow this. but i'm not sure all file systems do. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to make sure that the target file to read is not under writing by others?
On 8/19/09 3:55 AM, Dengxule dengx...@gmail.com wrote: I have a crontab command to execuate my php-script every half an hour. The mission of the php-script is to open a file(log file), examine it. The target file(log file) is transported to local every half an hour. I've no idea how much time it will costs and on the other hand, i want to make sure the file i'm openning is Completely Written. Any instruction will be grateful. perhaps you could use cronolog (http://cronolog.org/) to rotate the log files every half hour? that way you could be sure that the file you open to process/copy is one that cronolog has finished writing to. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help on pregreplace
On 8/18/09 10:56 AM, Merlin Morgenstern merli...@fastmail.fm wrote: Ashley Sheridan wrote: On Tue, 2009-08-18 at 16:00 +0200, Merlin Morgenstern wrote: Hi there, I am highlighting keywords with the help of pregreplace. This works great with one limitation. If the word that has to be replaced contains a slash, preg throws an error. So far I could not find a fix. Can someone help? Here is the code: $pattern = /\b($words)\b/is; $replace = 'span style=background:#FF;color:#FC;\\1/span'; return preg_replace($pattern,$replace,$str); Thank you in advance, Merlin Well, a slash has a special meaning inside PHP strings, more so for double quoted strings. Are you correctly escaping the slash as a double slash so that it's not interpreted by the string as an escaped character, as you will need to as the preg_replace will be interpreting it as an escape sequence to match? Thanks, Ash http://www.ashleysheridan.co.uk HI, replacing the delimiter slash by ~ solved the problem. Thank you which means that words with ~ in them will fail. as Al pointed out, preg_quote() is a more general solution. it escapes all tricky pcre characters as well as the delimiter. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is there a better way to know from which php file the request comes from ??
On 8/17/09 5:24 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Mon, 2009-08-17 at 02:17 -0700, nashrul wrote: This is a newbie question... Let's say there are 3 php files, page1.php, page2.php and page3.php. Form submission from page1.php or page2.php will take user to page3.php. I know that we can use parameter that is appended in the action attribute of the form (e.g FORM METHOD=POST ACTION=tes.php?var1=val1) But I think, appending this parameter is transparent to the user, since it's visible in the url. And I think we can also use the hidden field or (form name ??.). So which one is most secured and better ?? Thanks.. -- View this message in context: http://www.nabble.com/is-there-a-better-way-to-know-from-which-php-file-the-r equest-comes-fromtp25003587p25003587.html Sent from the PHP - General mailing list archive at Nabble.com. Neither GET or POST is more secure, it's just that POST requires a tiny bit more work to see what's being sent. You can use the $_SERVER['HTTP_REFERER'] variable to detect where a request has come from. The documentation for this particular variable mentions that it can't be trusted, as it can be changed by the client browser, but then, so can hidden form fields, etc. Personally, I'd go with the HTTP_REFERER route, because it is completely transparent, and the majority of users aren't going to bother changing it. your probably right. though i remember when i considered using HTTP_REFERER. i looked up the http rfc and it said that use of the header was optional. that made sense. so i decided not to make any of app functionality depend on it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is there a better way to know from which php file the request comes from ??
On 8/17/09 5:17 AM, nashrul anas_a...@yahoo.com wrote: This is a newbie question... Let's say there are 3 php files, page1.php, page2.php and page3.php. Form submission from page1.php or page2.php will take user to page3.php. I know that we can use parameter that is appended in the action attribute of the form (e.g FORM METHOD=POST ACTION=tes.php?var1=val1) But I think, appending this parameter is transparent to the user, since it's visible in the url. And I think we can also use the hidden field or (form name ??.). So which one is most secured and better ?? i'm not in love with using the form POST method combined with an action url that includes pseudo-GET parameters. for POST forms, i use a convention of always having a hidden input in the form to indicate which form sent the query, e.g. input type=hidden name=whichform value=foobarform this also comes in handy if one server script processes more than one form. as for security, there's little difference between this method, using GET values, using HTTP_REFERER, or what have you. protection against spoofing lies not in these choices. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] where does CURLOPT_QUOTE output go?
just for example's sake, say i were doing something like $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'ftp://user:p...@server/dir/filename'); curl_setopt($ch, CURLOPT_UPLOAD, true); curl_setopt($ch, CURLOPT_FILE, $outfileh); curl_setopt($ch, CURLOPT_INFILE, $infileh); curl_setopt($ch, CURLOPT_STDERR, $stderrh); curl_setopt($ch, CURLOPT_POSTQUOTE, array(STAT,FEAT)); to upload a file via ftp. (assume my file handles are all set up correctly.) where do the replies from the FTP server to the STAT and FEAT commands end up? not in $outfile, i've confirmed. the only thing i've come up with is to set verbose and parse stderr. ick! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] curl_exec not hit server
On 8/6/09 2:33 PM, Ted Yu ted...@yahoo.com wrote: Hi, I use the following code to call third party web service: curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_SSLVERSION, 3); curl_setopt($ch, CURLOPT_SSLCERT, $loc); curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $password); curl_setopt($ch, CURLOPT_HTTPHEADER, $this-_httpHeaders); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $this-_xmlData); $ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $xmlResponseData = curl_exec($ch); But for a specific API, curl_exec() returns true but there was no hit on their server (as verified by contact in that company from server log) Can someone provide hint ? not me. but, if you haven't already, maybe try debugging by: print out the values of all the variables in the above code and with them (or some subset) try making the same (or similar, or simpler) requests to the same $url using curl the command line with verbosity or tracing turned on. curl might give the hint you need. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: This is the kind of [expletives deleted] answer that is certain to prevent bugs being reported.
On 7/25/09 6:27 AM, Per Jessen p...@computer.org wrote: Lupus Michaelis wrote: Per Jessen wrote: See http://bugs.php.net/?id=48612 I don't understand too the answer. For me it is obvious it is a bug because it breaks the system locale behaviour. Thanks, I'm glad I'm not alone in thinking this. to many people, a documented bug is like a false truth: it simply cannot exist. the premise is that a bug, by definition, is not documented. if it's documented then it's a feature and a feature is never also a bug. i'd wager that one devotee of this doctrine would be the bug checker who shot off that superior, sneering insult in the disposition of your bug report. if that response was a standard text built into the bug management system then it suggests the doctrine pervades the culture on the team. in my view, the premise doesn't hold up very well. we can all think of bugs that could not reasonably be be debugged by documenting them. hence there is a zone in the spectrum between obvious bug and obvious non-bug. saying go away and rtfm when discussing behaviors in this zone is not respectful. failure of a cli program to behave idiomatically under unix (or that finnish os that shares so many of the idioms) is arguably a bug -- it's in that zone. the response you got, per, was a cheap brush-off. btw: i think setlocale() is not the right place to document the feature that php cli ignores standard environment variables. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] unsetting a referenced parameter in a function
though the manual is perfectly clear that this should be expected, i was a bit surprised that the result of the following is 42 ?php function foo($a) { $a = 42; unset($a); $a = 'meaning'; } foo($a); print($a\n); ? normally i would expect unset() to free some memory. but in this example it doesn't and has a different behavior: it releases foo's reference to the global $a, allowing the next line to define a local $a. i think i'd have preferred compile error. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: unsetting a referenced parameter in a function
On 7/22/09 6:09 PM, Shawn McKenzie nos...@mckenzies.net wrote: Tom Worster wrote: though the manual is perfectly clear that this should be expected, i was a bit surprised that the result of the following is 42 ?php function foo($a) { $a = 42; unset($a); $a = 'meaning'; } foo($a); print($a\n); ? normally i would expect unset() to free some memory. but in this example it doesn't and has a different behavior: it releases foo's reference to the global $a, allowing the next line to define a local $a. i think i'd have preferred compile error. Well, you unset the reference and then you assigned 'meaning' to a local function variable $a. Why would you get a compile error? when you state it in those terms (which are clearly correct) i wouldn't. but if the way i think is unset() destroys the specified variables (as the manual puts it) then i expect that the specified variable would be destroyed, not the reference. so, as i said, i was a bit surprised when the variable wasn't destroyed. once i understood what was happening, i thought it a bit confusing to have such scope-dependent differences in behavior of a language element. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I have an idea
On 7/15/09 12:21 AM, Martin Scotta martinsco...@gmail.com wrote: Hi Do you noted that all the discussion here are about problems, bugs, or just urgent pleaaase help me I have an idea. It is not really THE idea... but it is. What happen if tell this idea to the community? I don't know, so, let's take a look. PHP is a great language. You can do a lot of things with him, even have fun with it. My idea is to make a simple game where your have to write some AI to beat the other players AI The idea, as simple as it looks, is really difficult to implement specially about security so, do you like me idea? like core wars? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to stop E_DEPRECATED messages in the PHP log?
On 7/7/09 1:23 AM, Jeff Weinberger j...@jeffweinberger.com wrote: On Jul 6, 2009, at 7:47 PM, Paul M Foster wrote: On Mon, Jul 06, 2009 at 02:16:09PM -0700, Jeff Weinberger wrote: Hi: I am hoping someone can help me figure this out I've just upgraded my PHP installation to 5.3.0. Now I am receiving thousands of log messages of the form PHP Deprecated: I know I have a number of scripts that use now-deprecated functions, etc. and I now know what those are, thanks to all the messages. However, this is now growing to (literally) gigabytes of log entries, so I'd like to stop the messages until I have the time to re-write all the offending scripts. I have tried the following error.reporting lines in php.ini: error_reporting = E_ALL ~E_DEPRECATED E_ERROR E_WARNING E_PARSE E_NOTICE E_CORE_ERROR E_USER_ERROR E_USER_WARNING E_USER_NOTICE E_COMPILE_ERROR E_COMPILE_WARNING error_reporting = ~E_DEPRECATED E_ALL E_ERROR E_WARNING E_PARSE E_NOTICE E_CORE_ERROR E_USER_ERROR E_USER_WARNING E_USER_NOTICE E_COMPILE_ERROR E_COMPILE_WARNING error_reporting = E_ALL E_ERROR E_WARNING E_PARSE E_NOTICE E_CORE_ERROR E_USER_ERROR E_USER_WARNING E_USER_NOTICE E_COMPILE_ERROR E_COMPILE_WARNING ~E_DEPRECATED error_reporting = E_ERROR E_CORE_ERROR E_USER_ERROR E_COMPILE_ERROR E_COMPILE_WARNING ~E_DEPRECATED error_reporting = ~E_DEPRECATED E_ERROR E_CORE_ERROR E_USER_ERROR E_COMPILE_ERROR E_COMPILE_WARNING (as you can tell, I prefer verbose logs, but not that verbose...). None of these combinations have stopped the PHP Deprecated: ... messages. System info: Mac OS/X 10.5.7 Client version, PHP 5.3.0 running as a CGI under Apache 2.2.11 and as a CLI. Please let me know if there's any other info that might help. php_info() reports error.reporting as 0 Any help or guidance is appreciated!! Try error_reporting(E_ALL ^ E_DEPRECATED); See http://us2.php.net/manual/en/function.error-reporting.php for more info and examples. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Paul: Thanks for your suggestion - it would work nicely, except that that is a runtime function that is called within a script. I am trying to get the php.ini setting correct to avoid the Deprecated messages. I tried error_reporting=E_ALL ~E_DEPRECATED (which I think is the php.ini analogy to your suggestion) to no avail - it failed also. leaving me still confused how about running this to find the int value to put into php.ini: ?php error_reporting(E_ALL ^ E_DEPRECATED); echo error_reporting(); ? i don't have 5.3 so i haven't tried. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to stop E_DEPRECATED messages in the PHP log?
On 7/7/09 11:38 AM, Daniel Brown danbr...@php.net wrote: On Tue, Jul 7, 2009 at 11:03, Jeff Weinbergerj...@jeffweinberger.com wrote: This seemed like it would be the perfect solution...but alas it did not work. 22527 seems right, but after changing php.ini to that and restarting php and apache, I am still getting Deprecated... messages. Dumb question, Jeff: are you sure you're editing the correct php.ini file? i was about to ask the same. phpinfo() will tell you the path to the in-effect config file. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to stop E_DEPRECATED messages in the PHP log?
On 7/7/09 12:17 PM, Jeff Weinberger j...@jeffweinberger.com wrote: On Jul 7, 2009, at 8:38 AM, Daniel Brown wrote: On Tue, Jul 7, 2009 at 11:03, Jeff Weinbergerj...@jeffweinberger.com wrote: This seemed like it would be the perfect solution...but alas it did not work. 22527 seems right, but after changing php.ini to that and restarting php and apache, I am still getting Deprecated... messages. Dumb question, Jeff: are you sure you're editing the correct php.ini file? -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Check out our great hosting and dedicated server deals at http://twitter.com/pilotpig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Daniel: Not a dumb question at all! I check every time (php_info()) to make sure the loaded configuration file is the one I'm editing. So, as far as I can tell, yes. Should I be looking at something else to be sure? i've now had a look at http://www.php.net/manual/en/errorfunc.constants.php in your shoes i'd try out 2047 (with is everything up to and including E_USER_NOTICE) and possibly 6143 (=2047+4096) if you have your own error handler. if still no luck i can't think of anything else to suggest but work backwards: check the value returned by error_reporting() is the value you set in php.ini. binary decode it to double check. if it sill makes no sense, check the php bugs db. and if nothing, maybe report it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Compare and inserting with php
On 6/30/09 11:17 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: It's a bad way of doing it, but could you not create a unique index on the particular key you want to be unique, and then just try the select anyway with the mysql_query() call preceeded with an @ to suppress warnings? if you're going that route and your DB supports it, use INSERT IGNORE. if the primary/unique key makes sense for the application then i don't think this is all that bad a way of doing things. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Best way to reinstate radio-button states from database?
On 6/29/09 10:26 PM, Michael A. Peters mpet...@mac.com wrote: Rob Gould wrote: I have a webpage which allows people to log in and make selections with radio buttons and hit SUBMIT and saves the data from those radio buttons to a mySQL database. However, I'm finding that I also need the ability to allow a user to log back in at a later date (or even on a different computer), and pull up that survey again, with each of the 50-something radio-buttons back in the positions in which they were last saved. Surely there's a best-case-method for doing this type of thing (saving large numbers of radio-button-group settings to mySQL and pulling them back again later). Any advice is greatly appreciated. Perhaps there's a jQuery-way to retrieve all the radio-button group settings as an array and save it and pull it back again? Or perhaps a PHP-specific method - - - I'm fine with either. Generate your radio list via php. When the value grabbed from database matches the button value, add a selected=selected to the radio input. Works for me. michael: radios and checkboxes take the checked attribute -- options in selects take the selected attribute. http://www.w3.org/TR/html401/interact/forms.html#checkbox rob: if you use systematic naming of the radio input elements (e.g. a common prefix) then you can use a simple loop to generate an SQL query from the $_POST array to store the form state as a string. then use another loop to generate the markup for all your radios, inserting the checked attribute for those radios whose names appear in the string you stored in the DB. the key is the systematic naming and having a page design (and maybe template scheme, if you like) that allows simple automated generation of the form's markup. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_query blocking
On 6/27/09 7:09 PM, Daniel Kolbo kolb0...@umn.edu wrote: Tom Worster wrote: On 6/27/09 3:15 PM, Daniel Kolbo kolb0...@umn.edu wrote: When a MySQL table is locked a php call of mysql_query() that requires that table will hang as the request blocks at the MySQL server until the table is unlocked. Is there a way to stop a mysql_query from hanging (by setting a time limit)? would it be possible to test for presence of the lock before issuing the query that would block? if so, you could check the lock periodically until your time limit is up. would achieve you you're looking for? it would still be possible that after checking but before issuing the query the table's could be locked - albeit a much smaller chance. that's true. what would be nice for this kind of problem would be a kind of async api, perhaps a bit like curl_multi but with a way to check the state of an outstanding query (queued, processing, etc). much like a js script uses ajax. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql_query blocking
On 6/27/09 3:15 PM, Daniel Kolbo kolb0...@umn.edu wrote: When a MySQL table is locked a php call of mysql_query() that requires that table will hang as the request blocks at the MySQL server until the table is unlocked. Is there a way to stop a mysql_query from hanging (by setting a time limit)? would it be possible to test for presence of the lock before issuing the query that would block? if so, you could check the lock periodically until your time limit is up. would achieve you you're looking for? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] This Friday's OT Thread
and Kaleem Omar. and 15 people in Baghdad when motorcycle loaded with nails and ball-bearings exploded in a crowded bazaar. On 6/26/09 4:27 AM, Robert Cummings rob...@interjinn.com wrote: Farah Fawcett has also died. I guess you gotta go sometime :| Björn Bartels wrote: Hello fellow coders... THE 'KING OF POP' IS DEAD ! Tonight (here in Germany), Mr. Michael Joseph Jackson, also known as 'the king of pop', died on heart failure in the age of 50. I just want to express my condolences to his family and friends and all the people who loved him and his music. This incomparable legendary musician has made such a big impact on music and musicians than any other artist in history. Rest in peace, Mr. Jackson! And may you and your music never be forgotten... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] This Friday's OT Thread
On 6/26/09 9:20 AM, Michelle Konzack linux4miche...@tamay-dogan.net wrote: ...and no one care about the foreign (european) sniper WHO killed Neda in Iran. i don't know why you'd think that. the story is all over the news. american pols have been exploiting it. cnn reports cia hay have been behind the shooting. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: aesthetic beauty in conception, execution
On 6/18/09 12:35 PM, PJ af.gour...@videotron.ca wrote: Peter Ford wrote: PJ wrote: I just thought I would share a revelation. Someone just pointed me to a site that IMHO is superb for elegance of artistic design and programming. I was blown away. http://www.apfq.ca You won't regret it. 8-) Il y a seulement une problème - je ne lis pas Française... I18N - it's important, you know... close enough... it wold still be great even if it were in Esperanto - it's not the content, its the look, the presentation ?!?! any reliance stock photos of happy beautiful people doing fun or productive things is just lame. was already 10 years ago. the presentation looks like one of those domain sitting sites you get when you type a uri wrong. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] inserting blobs into mysql
i'm having trouble getting binary data into blobs in mysql. to help debug, i set up a test db and discovered that when i insert a binary string encoded using mysql_real_escape_string (according to the php manual: If binary data is to be inserted, this function must be used.), only byte values lower than 128 are accepted. all bytes in the string with value greater equal 128 are stripped out upon insertion, regardless where they appear in the string. so, for example if i create a test binart string thus: $data = ''; for ( $n=0; $n=127; $n++ ) $data .= chr($n) . chr($n+128); and inset it (using mysql_real_escape_string), the blob value that appears as viewed with phpmyadmin is only 128 bytes long. and when i select it, the value i get back is the same as if i had inserted: $data = ''; for ( $n=0; $n=127; $n++ ) $data .= chr($n); any idea why? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Totally weird behavior trying to download a Mac DMG file
On 6/16/09 1:40 PM, Brian Dunning br...@briandunning.com wrote: However, when I complete a test purchase and download using the above code, the DMG file downloads, but then it mounts; the contents are copied into the Downloads folder; the image unmounts; and then deletes. All the contents are delivered, but not in a desirable way. what headers are sent by the server when you don't use your php script? try sending those headers instead. perhaps try application/force-download as the content type instead. for several user agents this seems to prevent then from doing something useful with the file and just save it instead. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: inserting blobs into mysql
false alarm. the error was in my mysql abstraction class. some time ago i put a function in there to clean up invalid utf8 strings and it was doing a nice job on my binary strings. On 6/17/09 1:24 PM, Tom Worster f...@thefsb.org wrote: i'm having trouble getting binary data into blobs in mysql. to help debug, i set up a test db and discovered that when i insert a binary string encoded using mysql_real_escape_string (according to the php manual: If binary data is to be inserted, this function must be used.), only byte values lower than 128 are accepted. all bytes in the string with value greater equal 128 are stripped out upon insertion, regardless where they appear in the string. so, for example if i create a test binart string thus: $data = ''; for ( $n=0; $n=127; $n++ ) $data .= chr($n) . chr($n+128); and inset it (using mysql_real_escape_string), the blob value that appears as viewed with phpmyadmin is only 128 bytes long. and when i select it, the value i get back is the same as if i had inserted: $data = ''; for ( $n=0; $n=127; $n++ ) $data .= chr($n); any idea why? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] truncate a mb-string to a given octet length?
eddie, you were quite right and i was wrong. after discovering that the longest utf8 varchar column that mysql will allow is varchar(333), i did some tests. on a varchar(255) column, mysql allows strings with up to 255 utf8 characters to be inserted. and it truncates at 255 characters observing utf8 character sequences. now i have to go back to the script that convinced me otherwise and figure out what i misunderstood in it. section 10.4.1 of the manual could be explicit about it. when i read it i got the clear impression the parameter referred to octets. On 6/12/09 1:22 PM, Tom Worster f...@thefsb.org wrote: On 6/12/09 11:52 AM, Eddie Drapkin oorza...@gmail.com wrote: Correct me if I'm wrong, but should varchar 255 with a utf8 character set mean 255 unicode characters, not octets? in mysql, the length refers to the storage space of the string, not the decoded character count. i don't know about other dbms. On Fri, Jun 12, 2009 at 11:50 AM, Tom Worster f...@thefsb.org wrote: say a table in the db has a varchar(255) column, 255 being the max number of octets of strings that can go in the column. now say the php script very occasionally has to deal with utf8 input strings with octet length 255 -- it needs to select rows matching the input string or insert the input string. so what i think i need is a function to truncate a utf8 string to the longest valid utf8 string that has octet length = 255. is this what mb_strcut() is for? i'm having a hard time understanding the man page for that function. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] truncate a mb-string to a given octet length?
say a table in the db has a varchar(255) column, 255 being the max number of octets of strings that can go in the column. now say the php script very occasionally has to deal with utf8 input strings with octet length 255 -- it needs to select rows matching the input string or insert the input string. so what i think i need is a function to truncate a utf8 string to the longest valid utf8 string that has octet length = 255. is this what mb_strcut() is for? i'm having a hard time understanding the man page for that function. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: truncate a mb-string to a given octet length?
On 6/12/09 11:50 AM, Tom Worster f...@thefsb.org wrote: say a table in the db has a varchar(255) column, 255 being the max number of octets of strings that can go in the column. now say the php script very occasionally has to deal with utf8 input strings with octet length 255 -- it needs to select rows matching the input string or insert the input string. so what i think i need is a function to truncate a utf8 string to the longest valid utf8 string that has octet length = 255. is this what mb_strcut() is for? i'm having a hard time understanding the man page for that function. i satisfied myself that mb_cutstr() probably does what i need with the following: $default_locale = setlocale(LC_ALL, 'en_US.UTF-8'); ini_set('default_charset', 'UTF-8' ); $strs = array( 'Iñtërnâtiônàlizætiøn', 'החמאס: רוצים להשלים את עסקת שליט במהירות האפשרית', 'ايران لا ترى تغييرا في الموقف الأمريكي', '独・米で死傷者を出した銃の乱射事件', '國會預算處公布驚人的赤字數據後', '이며 세계 경제 회복에 걸림돌이 되고 있다', 'В дагестанском лесном массиве южнее села Какашура', 'นายประสิทธิ์ รุ่งสะอาด ปลัดเทศบาล รักษาการแทนนายกเทศมนตรี ต.ท่าทองใหม่', 'ભારતીય ટીમનો સુવર્ણ યુગ : કિવીઝમાં પણ કમાલ', 'ཁམས་དཀར་མཛེས་ས་ཁུལ་དུ་རྒྱ་གཞུང་ལ་ཞི་བའི་ངོ་རྒོལ་', 'Χιόνια, βροχές και θυελλώδεις άνεμοι συνθέτουν το', 'Հայաստանում սկսվել է դատական համակարգի ձեւավորումը', 'რუსეთი ასევე გეგმავს სამხედრო'); foreach ( $strs as $s ) { for ( $i=10; $i100; $i+=10) { $t = mb_strcut($s, 0, $i); $ok = mb_check_encoding($t, 'UTF-8') ? 'OK' : 'Bad'; print($i\t . mb_strlen($t, 'ISO-8859-1') . \t . mb_strlen($t, 'UTF-8') . \t$ok\t$t\n); } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] detect cli sapi
what's a reliable way to detect that the sapi is cli, including in a included scripts? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php applications
On 6/8/09 12:30 PM, Kyle Terry k...@kyleterry.com wrote: I don't mean to be the thread spirit killer, but I think another language would be better for this. Such as Python. PHP desktop apps might be fun to hack around with, but I wouldn't use it for a production application. if there were a cocoa interface as there is for python or ruby, i'd probably use it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php applications
On 6/8/09 4:26 PM, Dee Ayy dee@gmail.com wrote: Not as smooth as Xcode and Interface Builder eh? no -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Outputting File To The Browser Failed And Kill Apache
if the problem is due to flow control issues between the script and the httpd server then perhaps changing the approach could help. i quit using this approach of writing files to the php output buffer a little while ago. it seemed that it was better to leave the flow control issues entirely to apache. so i wrote the file to a specific directory on the server and redirected the client to it, using the apache directive on that directory: Header set Content-Disposition attachment you can use that directive to send whatever headers you need. On 6/5/09 3:52 PM, Nitsan Bin-Nun nit...@binnun.co.il wrote: Hi List, I'm using the following code to output a file to the browser. Each file size is in the range of 5-10MB, all of them are MP3. header(Pragma: public); header(Expires: 0); header(Cache-Control: must-revalidate, post-check=0, pre-check=0); header(Cache-Control: public); header(Content-Description: File Transfer); header(Content-Type: {$info['mimetype']}); header(Content-Disposition: attachment; filename=\{$info['filename']}\); header(Content-Transfer-Encoding: binary); header(Content-Length: . $info['size']); set_time_limit(0); $file = @fopen($config['storage'][$config['current_storage']].$info['md5']...$info[ 'extension'],rb); if ($file) { while(!feof($file)) { print(fread($file, 1024*8)); flush(); if (connection_status()!=0) { @fclose($file); die(); } } @fclose($file); } I'm running this script on a VPS which has a 10MBIT connection. When I posted a link to this download stream php file about 50 users started download it, then the script stopped from sending the whole file (for instance, the file is 5MB, the script sends 2MB, 1MB and it continue this way). In the apache log file I have seen these lines, but I have no idea what are their meaning: [Fri Jun 05 22:02:28 2009] [error] (12)Cannot allocate memory: fork: Unable to fork new process [Fri Jun 05 22:02:38 2009] [error] (12)Cannot allocate memory: fork: Unable to fork new process [Fri Jun 05 22:02:48 2009] [error] (12)Cannot allocate memory: fork: Unable to fork new process [Fri Jun 05 22:11:35 2009] [error] (12)Cannot allocate memory: fork: Unable to fork new process I have no idea what's going on. Any ideas to solve this issue will be very appreciated. My 12K users are suffering right now, I would really really appreciate any idea in the right direction :) :) :) Thank you! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Anyone know whats the best way to learn PHP
On 6/1/09 6:43 AM, Muhammad Hassan Samee hassansa...@gmail.com wrote: Anyone know whats the best way to learn PHP? Every time I open an php book or look the codes online, my mind goes oh man, So many stuffs to learn and gets frustrated before i even start but on the other hand, I don't know why some how the brain keep on nagging me to learn PHP. I guess what's the fun way to learn php? Any good books? i've often tried to learn a language from a book and always failed. clearly this works for some folk, never has for me. i find the initial ramp of the learning curve very hard to take. it's daunting. but that's always true and anything really worth your time is going to be difficult. after doing hello world, think of a simple project of your own to tinker with as you learn. that's the generalities. as for php, if you already know a few programming languages, i think the the manual's chapter called language reference is not a bad place to start. lots of examples. systematic one language feature at a time. skip stuff that really makes no sense, you can lear those bits later. you'll forget most of it but you'll know where to find it when you need it. try things out in your sample project. once you're programming and getting stuff done, reading other people's code is great. there's lots available (e.g. in pear). but don't assume it's all a model for what you should do, it's just examples of what can be done -- good, bad and indifferent. good luck -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP vs ASP.NET
assuming one had suitable hardware, what does it cost to start developing for asp? i guess you'd need to buy a copy of some windows server for dev test. what else? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] detecting spam keywords with stripos
On 5/29/09 5:36 AM, Merlin Morgenstern merli...@fastmail.fm wrote: Does somebody have an idea on how to make my function better in terms of not detecting the string inside a word? i agree with per. learn pcre: http://us.php.net/manual/en/book.pcre.php as for successfully filtering spam by keyword matching: good luck! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Hebrew Directory Names
On 5/28/09 2:06 PM, Nitsan Bin-Nun nit...@binnun.co.il wrote: preg_replace(/([\xE0-\xFA])/e,chr(215).chr(ord(\${1})-80),$s); ... The preg_replace() above convert the Hebrew chars into UTF8. that preg_replace takes a byte string $s and: - leaves bytes with value 0-127 intact - converts bytes with value 224-250 to the utf8 multibyte character code of the corresponding win-1255 character - produces an invalid utf8 output for all other code points, for which see: http://en.wikipedia.org/wiki/Windows-1255 so it's a win-1255 to utf-8 converter only so long as you are confident that code points 128-223 and 251-255 are never in the subject string. try iconv('CP1255', 'UTF-8', $s) instead. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Create multipart email
guus, take a look at: http://pear.php.net/manual/en/package.mail.mail-mime.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Confirmation email caught by spam filter
On 5/28/09 3:20 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: Would setting up a backup MX record solve this do you think? this is what the spf record is for. http://en.wikipedia.org/wiki/Sender_Policy_Framework -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Hebrew Directory Names
On 5/28/09 10:15 AM, Nitsan Bin-Nun nit...@binnun.co.il wrote: I have wrote a files-based php system which not requires any kind of database to work, it is based upon files and directories. I'm using scandir() to fetch the file names of a directory, when the files and the directories are in English everything works like a charm, the problems starting when the files or the directories are in Hebrew. I tried several encodings for the directory names (including UTF8) but no luck so far. I always get is_file() === FALSE when the directory name is in Hebrew and the filename is in English. Any ideas?? The path which I'm checking with is_file() is: string(63) /home/nitsanbn/public_html/iphoneia/walls/מחשבים/1346.jpg (Due to the LTR encoding of this messege the filename is looking like it's in Hebrew, the directory is מחשבים and the filename is 1346.jpg) interesting problem. i suspect there will be serious dependency on os and file system. on os x 10.5 and a Mac OS Extended volume i created a directory with 5 files in it as follows: $ ls במהירות אתעסקתשליטרוציםלהשלים (i've no idea what these words mean. i copied them from a hebrew newspaped web site.) i ran the following script with cwd set to the ditectory in php 5.2.8 cli: $default_locale = setlocale(LC_ALL, 'en_US.UTF-8'); ini_set('default_charset', 'UTF-8' ); $dh = opendir('.'); while (false !== ($filename = readdir($dh))) $files[] = $filename; sort($files); print_r($files); foreach ($files as $f) print( (is_file($f) ? file:\t\t : not file:\t).realpath($f).\n ); Array ( [0] = . [1] = .. [2] = את [3] = להשלים [4] = עסקת [5] = רוצים [6] = שליט ) not file:/Users/fsb/במהירות not file:/Users/fsb file:/Users/fsb/במהירות/את file:/Users/fsb/במהירות/להשלים file:/Users/fsb/במהירות/עסקת file:/Users/fsb/במהירות/רוצים file:/Users/fsb/במהירות/שליט ok. but as you noted, the ltr reversal switches path order as well as character order, which is a bit confusing. (btw: the square brackets above got reversed in the cut and paste from terminal window to entourage.) then i renamed the files thus: $ ls את.jpgשליט.jpgלהשלים.jpg עסקת.jpgרוצים.jpg $ ls -l total 0 -rw-r--r-- 1 fsb fsb 0 May 28 12:16 את.jpg -rw-r--r-- 1 fsb fsb 0 May 28 12:16 עסקת.jpg -rw-r--r-- 1 fsb fsb 0 May 28 12:59 שליט.jpg -rw-r--r-- 1 fsb fsb 0 May 28 12:16 רוצים.jpg -rw-r--r-- 1 fsb fsb 0 May 28 12:16 להשלים.jpg which is also a tad confusing, ls using two different conventions. but the script still seems to work. Array ( [0] = . [1] = .. [2] = את.jpg [3] = להשלים.jpg [4] = עסקת.jpg [5] = רוצים.jpg [6] = שליט.jpg ) not file:/Users/fsb/במהירות not file:/Users/fsb file:/Users/fsb/במהירות/את.jpg file:/Users/fsb/במהירות/להשלים.jpg file:/Users/fsb/במהירות/עסקת.jpg file:/Users/fsb/במהירות/רוצים.jpg file:/Users/fsb/במהירות/שליט.jpg now with a couple of numeric file names in the same directory: $ ls 1234.jpgעסקת.jpgלהשלים.jpg 2345.jpgשליט.jpg את.jpgרוצים.jpg Array ( [0] = . [1] = .. [2] = 1234.jpg [3] = 2345.jpg [4] = את.jpg [5] = להשלים.jpg [6] = עסקת.jpg [7] = רוצים.jpg [8] = שליט.jpg ) not file:/Users/fsb/במהירות not file:/Users/fsb file:/Users/fsb/במהירות/1234.jpg file:/Users/fsb/במהירות/2345.jpg file:/Users/fsb/במהירות/את.jpg file:/Users/fsb/במהירות/להשלים.jpg file:/Users/fsb/במהירות/עסקת.jpg file:/Users/fsb/במהירות/רוצים.jpg file:/Users/fsb/במהירות/שליט.jpg so it looks like things are working here. i was unable to do anything hebrew at all on in your position i would check the default charset and locale settings. also perhaps try a different php version. i expect you have mbstring installed. i have mbstring.func_overload = 7 mbstring.internal_encoding = UTF-8 but i doubt that makes the difference. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP, OOP and AJAX
On 5/28/09 7:31 AM, Julian Muscat Doublesin opensourc...@gmail.com wrote: I had been programming in ASP.NET for years using Object Oriented Princeliness but decided to walk away from that. I am now researching and specialising in the open source world. yay! I have started to develop a project using MySQL, PHP and OOP. oh. not walking away from oop after all? sad ;-) So far I have succeed. However I got stuck once I started implement AJAX using the AJAX tutorial from w3schools.com. if using ajax, i recommend you take a look at jquery. i'm really quite taken with it. it makes browser-independent ajax much easier. What I have discovered is: for some reason when you call a file that requires other fies using the REQUIRE or INCLUDE it just does not work. I can conform this as I have tested with out the the functions. i can't imagine a reason why an include would fail because the script was invoked via XHR. my ajax back-end php scripts use included files. are you sure this isn't a problem with the include path? to debug you could try writing ini_get('include_path') to your log file. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP vs ASP.NET
On 5/28/09 9:20 AM, Olexandr Heneralov ohenera...@gmail.com wrote: I have a question for everyone: Can it happen so that PHP will be replaced with ASP.NET? why you pry it out of my cold dead hand ;-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Hebrew Directory Names
On 5/28/09 1:19 PM, Tom Worster f...@thefsb.org wrote: i suspect there will be serious dependency on os and file system. i was unable to do anything with hebrew file or dir names on freebsd 7.1 with ufs. i even tried scping and tarring over the directory that worked on os x. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Hebrew Directory Names
On 5/28/09 2:06 PM, Nitsan Bin-Nun nit...@binnun.co.il wrote: i have tried this: ?php if (!defined('THROUGH_INDEX')) die('Sorry mate!'); $default_locale = setlocale(LC_ALL, 'en_US.UTF-8'); ini_set('default_charset', 'UTF-8' ); $_GET['folder'] = preg_replace(/([\xE0-\xFA])/e,chr(215).chr(ord(\${1})-80),$_GET['folder'] ); $dirname = $config['walls_dir'].$_GET['folder']./.$_GET['filename']; if (!is_file($dirname)) { echo leave();; g($dirname);die;} I'm still getting: leave(); string(56) /home/nitsanbn/public_html/iphoneia/walls/חלל/008.jpg The preg_replace() above convert the Hebrew chars into UTF8. The conversion does work but the file is not recognized as a file, although that i can browse it straightly. why do you think that you need to do any conversion at all? that preg_replace looks terrifying! how did you come by it? i'm immediately suspicious that this is the problem. i googled the code and found people claiming that it translates window-1255 to utf8 (2004, dubious) and iso-8859-1 to utf-8 (2005, dubious). if you know that the browser is sending the GET variable 'folder' in a known encoding other than utf8, why not convert it with mb_convert_encoding or iconv? alternatively, force the user agent to send it in utf8 by sending the form as utf 8 (send header('Content-Type: text/html; charset=utf-8'), and use accept-charset=utf-8 in the form tag) and don't convert. then you can avoid all conversions. I'm afraid that I don't have access to the php.ini, since it's a shared hosting, do you know if hostgator gives access to php.ini or let you changes it's values? i have no idea. but i imagine it is sufficient to use ini_set(). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] continue working after finishing up with the http client
what options are there to do the following: 1. receive request from client (including post data) 2. do some work, update the db, prepare output for client 3. send output and finish up with the client 4. do some more work that might take considerable time, updating the db some more it would be convenient and efficient if step 4 took place within the same process as steps 1-3. but output control seems not to be sufficient: ob_flush(); flush(); sends the output but leave the client waiting for more. is there a way to close the connection as though exit; were called but without quitting the script? alternatively the script could start another process, copy over whatever data is needed and disconnect from it. but that has its overheads on the server. are the other possibilities? tia tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] continue working after finishing up with the http client
On 5/27/09 9:50 AM, bruce bedoug...@earthlink.net wrote: exacly what are you trying to accomplish? is this in a web app? has the user hit the site, logged in, etc? can you provide an example of what the sequence of events are that you're trying to deal with.. it is a web app. let's say for example that we're processing an ajax query. say we can normally generate and deliver the response to the client quickly but the speed depends on a cache with a relatively low miss rate. now, when we get a cache miss, imagine that generating the client response from scratch takes significantly less time than generating and inserting the new cache entry corresponding to the query. so we want to send the response to the client and then process the cache entry. without getting into whether or not this cache design makes sense, my question in this example is: what options are there for ending the http transition and then continuing on to do the cache update work? -Original Message- From: Tom Worster [mailto:f...@thefsb.org] Sent: Wednesday, May 27, 2009 6:27 AM To: php-general@lists.php.net Subject: [PHP] continue working after finishing up with the http client what options are there to do the following: 1. receive request from client (including post data) 2. do some work, update the db, prepare output for client 3. send output and finish up with the client 4. do some more work that might take considerable time, updating the db some more it would be convenient and efficient if step 4 took place within the same process as steps 1-3. but output control seems not to be sufficient: ob_flush(); flush(); sends the output but leave the client waiting for more. is there a way to close the connection as though exit; were called but without quitting the script? alternatively the script could start another process, copy over whatever data is needed and disconnect from it. but that has its overheads on the server. are the other possibilities? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] continue working after finishing up with the http client
On 5/27/09 12:35 PM, bruce bedoug...@earthlink.net wrote: hi tom... if i understand your state diagram/workflow process. your server repsonds to the client request, with two actions... action 1) return data to client relatively fast action 2) insert the data into your cache (or whereever) which takes time... is this correct? sure. but it was just an example of use of such an output and connection control technique. do you have to somehow use the 'new'/updated cache data in the future actions with the client... this was part of the example, yes. but another example could be that you process a web client's html form request, then send the client its response, close the client connection and then proceed with a whole bunch of complex logging of what was done. it might be possible for you to have a setup, where you have an external cron process, or other continually running process that does the cache insertions yes. this is one of the proposals david otton made, both of which are reasonable but do not enjoy the convenience or efficiency of doing the end work (e.g. the cache insertion) in the same process and memory space as the script that did the front work (e.g. processed the cache miss and sent the ajax response). doing the end work in a separate process comes with the overhead of serializing and communicating data to the other process. i found a web page suggesting that you can get a client to close the connection if you set ignore_user_abort(), then send Connection: close and Content-Length: #octets headers, then send the response followed by ob_flush and flush. can't say i'm in love with this. http://waynepan.com/2007/10/11/how-to-use-ignore_user_abort-to-do-process-ou t-of-band/ -Original Message- From: Tom Worster [mailto:f...@thefsb.org] Sent: Wednesday, May 27, 2009 7:14 AM To: bruce; php-general@lists.php.net Subject: Re: [PHP] continue working after finishing up with the http client On 5/27/09 9:50 AM, bruce bedoug...@earthlink.net wrote: exacly what are you trying to accomplish? is this in a web app? has the user hit the site, logged in, etc? can you provide an example of what the sequence of events are that you're trying to deal with.. it is a web app. let's say for example that we're processing an ajax query. say we can normally generate and deliver the response to the client quickly but the speed depends on a cache with a relatively low miss rate. now, when we get a cache miss, imagine that generating the client response from scratch takes significantly less time than generating and inserting the new cache entry corresponding to the query. so we want to send the response to the client and then process the cache entry. without getting into whether or not this cache design makes sense, my question in this example is: what options are there for ending the http transition and then continuing on to do the cache update work? -Original Message- From: Tom Worster [mailto:f...@thefsb.org] Sent: Wednesday, May 27, 2009 6:27 AM To: php-general@lists.php.net Subject: [PHP] continue working after finishing up with the http client what options are there to do the following: 1. receive request from client (including post data) 2. do some work, update the db, prepare output for client 3. send output and finish up with the client 4. do some more work that might take considerable time, updating the db some more it would be convenient and efficient if step 4 took place within the same process as steps 1-3. but output control seems not to be sufficient: ob_flush(); flush(); sends the output but leave the client waiting for more. is there a way to close the connection as though exit; were called but without quitting the script? alternatively the script could start another process, copy over whatever data is needed and disconnect from it. but that has its overheads on the server. are the other possibilities? -- 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] continue working after finishing up with the http client
On 5/27/09 10:33 AM, David Otton phpm...@jawbone.freeserve.co.uk wrote: 2009/5/27 Tom Worster f...@thefsb.org: without getting into whether or not this cache design makes sense, my question in this example is: what options are there for ending the http transition and then continuing on to do the cache update work? You either continue processing then-and-there (exec(), or whatever) or you put the job in queue to be dealt with at your leisure. The queue is the better solution if you're concerned about processor load, as you can prioritise it. The exec() is simpler to implement. in the absence of a tidy way to close the http connection to the client in mid-php script, i think the queue will be my better bet. if i use mysql to implement the queue then i'll have some convenient options for handling it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Confirmation email caught by spam filter
On 5/27/09 12:07 PM, LAMP l...@afan.net wrote: The problem is the confirmation emails and reset password emails are very often caught by email filter and finish in Spam/Junk folder, or even stopped by ISP. What am I doing wrong, or what to do to improve the code? i've run into this. among many factors that can be involved, the sending smtp server needs to be in address block that isn't black listed anywhere, e.g. don't try sending from a comcast address. also, you server needs to handle greylisting. it may help to set an spf record. in one instance i ended up using a well known mail hosting provider and sending the mail to their smtp server with authenticated smtp over ssl, which can be done quite easily with pear mail. i.e. pay the hosting company to worry about getting the emails through. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] templating engine options
On 5/25/09 8:48 PM, Nathan Rixham nrix...@gmail.com wrote: Sancar Saran wrote: ?php $content = 'No Comments'; if(isset($comments) and is_array($comments) and count($comments) 0 ) { $content = ''; foreach( $comments as $index = $comment ) : $content. = a href='. $comment-link.'.$comment-title./a; endforeach; } ? h2Comments/h2 div id=comments ?=$content? /div index.php ob_start(); require('template.php'); echo ob_get_clean(); I'm still do not understand for complex template system requirement. I just _need_ the two abstracted. php must have no html in it html template must contain no php i can achieve that separation in phplib using blocks, i.e blocks of template that may be repeatedly replaced, hierarchically if so desired. presumably smarty has something equivalent. but, naturally, this doesn't meet your pull requirement. hoever, i sometimes find that some mixing is inevitable. for example, if i am listing music recordings but not using a table, just a list. my template might be (leaving out the classes and ids. and humor me in my old-fashioned tag preferences): !-- BEGIN songblock -- lib{artist}/b, {disk} i{label}/i/li !-- END songblock -- that works but if my database entry for a given disk has no information on the label then the html output looks a but nasty: libMika Miko/b, We Be Xuxa i/i/li which sort of works but offends my sensibilities. since phplib doesn't have a way to make a chunk of template conditional (other than with a block, which would become a pita as you can imagine from the above), i sigh, shrug and move the i/i in the conditional in the script. oh well. purity is idealistic. a possible solution would be to define macros in the template, maybe... {MACRO:label=, i{label}/i} that would give me an optional comma and get rid of the space if there's no label data while keeping all html out of the script. while this achieves the ideal of separation i'm not sure it's really more practical than the impurity of having some html bits in the script. having practical experience with just one approach i can only speak theoretically of the other. (btw: macros can in fact be done in phplib templates by putting each macro in a template file of its own, but that doesn't sound too practical in the long run, does it?) on another different topic, i would make independence of the output language a requirement of the template scheme. e.g. besides html, i use phplib templates to generate plain text emails, sql files, json ajax responses, whatever... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] templating engine options
thanks for taking the trouble to write your requirements. it made interesting reading. i've questions on three points below... On 5/25/09 6:44 PM, Nathan Rixham nrix...@gmail.com wrote: XSL Templates are near perfect, built for the job, and very powerful - but time hasn't favoured them well; and until (if ever) a wide spread adoption happens something else needs to fill the gap. i don't know xsl well, but from what i read it seems to be about taking data from one xml document and putting it into another. that sounds reasonable except that the data that i want to combine with my template (either pushing it pulling) is in php variable state, not an xml document. however, it seems that one could write a php template class that takes xslt template files and data from the script? one thing i wasn't clear about with xsl is whether or not there's any output language dependence? could i write a template to produce an sql file, or an email in russian? Push vs Pull. ... The freedom to be able to specify in template that... this is template module latest posts, it is bound to the data view (or data provider) latest posts(8) whilst overall combining template (page) is comprised of modules x,y and z - here, here and here. ...really appeals to me; certainly in this scenario where you request (pull) from the application rather than make it all available. This way you only ever perform the business logic required for the information available. The counter part of making everything available incase it may be used is ridiculous (and makes me think coldfusion for some reason??). Architecturally this appears to be good - it's the presentation tier being a presentation tier, the logic tier knows nothing of the presentation tier and simply serves up what is requested. However thats only on the one side of the tier - on the other side we have a huge gaping hole where functionality should be (cache, compilation, delivery) etc, which would require another, as yet unknown layer (or 2). The abstraction and separation of concerns in this setup really appeals - but practically I'm not sure if the time spent implementing on a small or even medium sized project would be worth it. Still appeals massively though - pull makes more logical sense to me. Meanwhile, we have the first option, the way it's done, push the data - specify a template for that data and let template engine X do the merging. IMHO a clean, simple, lightweight implementation wouldn't be the hardest thing to make, and hundreds of apps are freely available all ready. i don't think i follow you. it seems you're saying that there would be some kind of an intermediate level of data representation that a script can be invoked to produce from which different templates can produce different outputs. but i can't see any difficulty in achieving similar modularity and reuse with available push template schemes and appropriate division of code among include files. one includable script generates the intermediate view while others use various templates to use it in output. so i think i'm missing something in your definition of pull. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] templating engine options
thanks for the pointers on xsl. i'll take a look. On 5/26/09 6:05 PM, Nathan Rixham nrix...@gmail.com wrote: it seems you're saying that there would be some kind of an intermediate level of data representation that a script can be invoked to produce from which different templates can produce different outputs. but i can't see any difficulty in achieving similar modularity and reuse with available push template schemes and appropriate division of code among include files. one includable script generates the intermediate view while others use various templates to use it in output. so i think i'm missing something in your definition of pull. yup, the modularity can be easily achieved using push, but with push you have to effectively send everything that can be needed to the template engine, then the template can either show all of it, some of it or whatever. but with this method of pull, the template would be pre-parsed to see what was required, then the app would generate and provide only what was needed for that specific template. Thus saving you generating a load of unneeded data incase the template might want to use it. clear? if not just say. it seems that you want to put certain parameters that configure the generation of the data that's to go into the output into the actual template files. if those parameters could instead be located in a php file somewhere then push would work as well. right? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] templating engine options
On 5/23/09 6:21 PM, Nathan Rixham nrix...@gmail.com wrote: Just a quick one, can anybody recommend any decent templating engines other than smarty. i started using phplib template in 2002. since then i've never bothered to revisit that choice. it may not qualify as an engine (all it does is juggle files and string values with regexp replacements) and probably isn't decent. but it offers sufficient flexibility for file, block and variable hierarchy and i find it meets my needs. i sometimes wonder if i am the only person still using it. it's in pear now: HTML_Template_PHPLIB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] templating engine options
On 5/25/09 10:04 AM, Stuart stut...@gmail.com wrote: Quick question, how would you implement the following using your XML-based template syntax... div class=option ?php if (!empty($option_class)) { echo $option_class; } ? ... /div It's worth noting that I'm simply suggesting a different way of looking at the world. If you have a templating system you're happy with then feel free to continue using it, but I'd encourage you to take the time to consider whether it actually gives you any tangible benefits. I've used Smarty as well as a number of proprietary templating systems and I'm yet to come across one that can justify its existence over simply using PHP. It's also worth noting that when I refer to a templating system I mean something that introduces an extra step when running a template. I consider the template classes I use to be a templating system but they do nothing but formalise the process of passing data to other PHP scripts and providing utility functions for them to use. revisiting the template question is interesting. i'm grateful for this discussion. as far as your question goes, with phplib-template, i'd do: div class=option {option_class} ... /div and in the php it is: $t-setVar('option_class', empty($option_class) ? '' : $option_class); or some equivalent code. $t is the template object. the interesting part is trying to explain why i like this better than your method. perhaps it's because it reduces the page assembly task to a sequence of regexp replacements and i'm more comfortable with that than i am with passing variable state to an included php file. why would i be? maybe i'm more comfortable looking at the world as nothing but strings and in this world, manipulating them is my job. there's certainly something i like about not having any php in my html templates but i can't say exactly what. i don't think i could come up with better justifications for my current methods without trying our the alternatives for a decent period. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] product listing columns
On 5/21/09 3:05 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: I'm advocating tables on this one, as it is pretty much tabular data. i too would put a table of product data in an html table. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: table-less layouts; Ideas welcome
On 5/21/09 5:06 AM, O. Lavell olav...@xs4all.nl wrote: Jim Lucas wrote: Since this has been a topic of dicussion, I figured I would add my thoughts. I have been toying with the idea of doing a table-less layouts involving tabular data, calendars, etc... Why? it's a zen practice. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php