Re: [PHP] Lightweight web server for Windows?
O. Lavell wrote: Also, it is not for daily use. I have two desktop computers and a server for that. This is for when I have to go by train or something. Essentially it is just an extra plaything. Does the battery still hold enough charge for a train journey - that always seems to be the first thing that goes on old laptops. They make really good low-power servers for stuff like DNS or even firewalling (as long as you can plug in enough network cards), but only when on mains power :( -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Does PHP block requests?
I have a tricky problem. I'm trying to make a progress feedback mechanism to keep users informed about a slowish process on the server end of a web app. The backend is generating a PDF file from a bunch of data which extends to many pages. I can keep tabs on the progress of this generation by working out how many lines of data is present, and how much of it has been processed. I use that information to set a session variable with a unique name - so for each step I set $_SESSION['some-unique-name']=Array('total'=$totalLines,'count'=$linesProcessedSoFar); Now on the front end I'm doing an AJAX call to a script that just encodes this session variable into a JSON string and sends it back. The problem is that while the PDF is being generated, the AJAX calls to get the progress data (on a 1-second interval) are being blocked and I don't get why. The PDF generation is also triggered by an AJAX call to a script which generates the PDF in a given file location, then returns a URL to retrieve it with. So it appears that the problem is that I can't have two AJAX calls to different PHP scripts at the same time? WTF? Checking the requests with Wireshark confirms the the browser is certainly sending the progress calls while the original PDF call is waiting, so it's not the browser side that's the problem: and once the PDF call is finished the outstanding progress calls are all serviced (returning 100% completion of course - not much use!) Different browsers (Firefox, IE, Chrome at least) give the same result. For reference, the server is Apache 2.2.10 on a SuSE linux 11.1 box using mod_php5 and mpm_prefork - is that part of the problem, and is there an alternative? -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Class not returning value
Pieter du Toit wrote: Hi This is my first class and it does not work, i do a return $this-responseArray; with the public function getResult() method, but get nothing. Can someone please help me. Thsi is how i create the object $number = new Smsgate($cell_numbers, $message, 27823361602, 27); $result = $number-getResult(); Here is the code: ?php /** * * @version 1.0 * @copyright 2009 */ /** */ class Smsgate { protected $number; protected $message; protected $sender_id; protected $tofind; private $result; /** * Constructor */ function __construct($number = , $message = , $sender_id = , $tofind = ) { $this-message = $message; $this-number = $number; $this-sender_id = $sender_id; $this-tofind = $tofind; } protected function display ($result) { return $result; } public function getResult() { return $this-processRequest(); } public function numberErrors() { return $this-errorResult; } /** * Smsgate::checknumbers() * * @return array of correct and incorrect formatted numbers */ private function processRequest() { echo nou by numers; print_r($this-number); // check if the property is an array and add to new array for sending if (is_array($this-number)) { // check for starting digits $this-result = ; // loop through numbers and check for errors foreach ($this-number as $this-val) { $this-position = strpos($this-val , $this-tofind); // number correct if ($this-position === 0) { echo is integer br/; if ($this-result != ) { $this-result .= ,; } // create comma seperated numbers to send as bulk in sendSMS method $this-result .= $this-val; //infobip multiple recipients must be seperated by comma // create an array to use with responseStringExplode in sendSMS method $this-cellarray[] = $this-val; echo Result is . $this-result . br; } else { // numbers not in correct format $this-errorResult[] = $this-val; } } //end foreach $this-sendSMS(); } else { $this-result = Not ok; return $this-result; } } private function sendSMS() { $this-smsUrl = 'http://www.infobip.com/Addon/SMSService/SendSMS.aspx?user=password='; $this-post_data = 'sender=' . $this-sender_id . 'SMSText=' . urlencode($this-message) . 'IsFlash=0GSM=' . $this-result; $this-sendData = $this-sendWithCurl($this-smsUrl, $this-post_data); $this-responseStringExplode = explode(\n, $this-sendData); $count=0; foreach ($this-responseStringExplode as $this-rvalue) { $this-responseArray[$this-rvalue] = ($this-cellarray[$count]); $count = ++$count; } return $this-responseArray; } private function sendWithCurl($url, $postData) { if (!is_resource($this-connection_handle)) { // Try to create one if (!$this-connection_handle = curl_init()) { trigger_error('Could not start new CURL instance'); $this-error = true; return; } } curl_setopt($this-connection_handle, CURLOPT_URL, $url); curl_setopt ($this-connection_handle, CURLOPT_POST, 1); $post_fields = $postData; curl_setopt ($this-connection_handle, CURLOPT_POSTFIELDS, $post_fields); curl_setopt($this-connection_handle, CURLOPT_RETURNTRANSFER, 1); $this-response_string = curl_exec($this-connection_handle); curl_close($this-connection_handle); return $this-response_string; } } ? Based on a first scan of your code, it looks like the only return in processRequest() is inside the else block, so nothing is returned unless the processing fails. -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: logic operands problem
Merlin Morgenstern wrote: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? Thank you in advance for any help! Merlin Surely what you need is xor (exclusive-or) I can't believe a programmer has never heard of that! (page==1 XOR page==2) AND page==3 -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Change displayed file name to download
You can set the name to display as you see fit, just change $filename to your liking right before the header() call. If you just want to cut the path, use basename($filename) Regards Peter On 14 March 2010 21:29, Php Developer pdevelo...@rocketmail.com wrote: Hi, I'm using the following code: $fp = fopen($filename, 'r+'); $content = fread($fp, filesize($filename)); fclose($fp); header(Content-type: application/msword); header(Content-Disposition: attachment; filename=$filename); echo $content; exit; ___ Now when downloading a file the default name that appears for the user is the realname of the file i the server with the real path the only difference is that the slashes are modified by underscore. My question is: is there any way how to control the name that will be displayed for the customer? Or at least skip the path and display just the file's name? Thank you __ Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail. Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.ca -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ldap_bind() connectivity
You might want to check what the function outputs with: var_dump($ldapbind); after the call to ldap_bing(). That way you'll know what actually got returned from the function. On 15 March 2010 09:54, Ashley M. Kirchner ash...@pcraft.com wrote: Thanks to Jochem Mass for helping earlier to the string splitting. Works great (so far). Now on to my next problem, which has to do with ldap_bind(). I have the following code: $ldapconn = @ldap_connect($adServer); $ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass); if ($ldapbind) { /** Successful authentication **/ $_SESSION['username'] = $username; $_SESSION['password'] = $password; } else { /** Authentication failure **/ $form-setError($field, laquo; Invalid username or password raquo;); } ldap_unbind($ldapconn); The problem with this is that if the ldap_bind() fails in the second line, it instantly spits text out to the browser: Warning: ldap_bind() [function.ldap-bind http://www.smartroute.org/contest/include/function.ldap-bind ]: Unable to bind to server: Invalid credentials in /home/contest/include/session.php on line 351 And because it does that, it never reaches the if routine right below it and everything just bombs. If I call it with @ldap_bind($ldapconn .) nothing happens. The error message gets suppressed but it also doesn't do anything with the if routine afterwards. It's almost like $ldapbind isn't getting set at all. What am I missing here? -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need routine to tell me number of dimensions in array.
This is one example where references actually decrease memory usage. The main reason is the recursive nature of the function. Try ?php echo memory_get_usage() . PHP_EOL; $array = range(0,100); $array[10] = range(0,10); $array[20] = range(0,10); $array[30] = range(0,10); $array[40] = range(0,10); $array[50] = range(0,10); $array[60] = range(0,10); $array[70] = range(0,10); $array[80] = range(0,10); $array[90] = range(0,10); $array[100] = range(0,10); echo memory_get_usage() . PHP_EOL; carray($array); function carray ($array) { foreach ($array as $value) { if (is_array($value)) carray($value); } echo memory_get_usage() . PHP_EOL; echo count($array) . PHP_EOL; } echo memory_get_usage() . PHP_EOL; And then compare with: ?php echo memory_get_usage() . PHP_EOL; $array = range(0,100); $array[10] = range(0,10); $array[20] = range(0,10); $array[30] = range(0,10); $array[40] = range(0,10); $array[50] = range(0,10); $array[60] = range(0,10); $array[70] = range(0,10); $array[80] = range(0,10); $array[90] = range(0,10); $array[100] = range(0,10); echo memory_get_usage() . PHP_EOL; carray($array); function carray ($array) { $i = 0; foreach ($array as $value) { if (is_array($value)) carray($value); } echo memory_get_usage() . PHP_EOL; echo count($array) . PHP_EOL; } echo memory_get_usage() . PHP_EOL; The memory usage spikes in the first example when you hit the second array level - you don't see the same spike in the second example. Regards Peter On 16 March 2010 15:46, Robert Cummings rob...@interjinn.com wrote: Richard Quadling wrote: On 15 March 2010 23:45, Daevid Vincent dae...@daevid.com wrote: Anyone have a function that will return an integer of the number of dimensions an array has? /** * Get the maximum depth of an array * * @param array $Data A reference to the data array * @return int The maximum number of levels in the array. */ function arrayGetDepth(array $Data) { static $CurrentDepth = 1; static $MaxDepth = 1; array_walk($Data, function($Value, $Key) use($CurrentDepth, $MaxDepth) { if (is_array($Value)) { $MaxDepth = max($MaxDepth, ++$CurrentDepth); arrayGetDepth($Value); --$CurrentDepth; } }); return $MaxDepth; } Extending Jim and Roberts comments to this. No globals. By using a reference to the array, large arrays are not copied (memory footprint is smaller). Using a reference actually increases overhead. References in PHP were mostly useful in PHP4 when assigning objects would cause the object to be copied. But even then, for arrays, a Copy on Write (COW) strategy was used (and is still used) such that you don't copy any values. Try it for yourself: ?php $copies = array(); $string = str_repeat( '*', 100 ); echo memory_get_usage().\n; for( $i = 0; $i 1000; $i++ ) { $copies[] = $string; } echo memory_get_usage().\n; ? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Need routine to tell me number of dimensions in array.
Hmm, will probably have to look inside PHP for this ... the foreach loop will copy each element as it loops over it (without actually copying, obviously), however there's no change happening to the element at any point and so there's nothing to suggest to the copy-on-write to create a new instance of the sub-array. It should look like this: $a = array(0, 1, 2, array(0, 1, 2, 3), 4, 5, 6, n); $b = $a[3]; doStuffs($b); Whether or not you loop over $a and thus move the internal pointer, you don't change (well, shouldn't, anyway) $b as that's a subarray which has it's own internal pointer, that isn't touched. Or maybe I've gotten this completely backwards ... Regards Peter On 16 March 2010 17:12, Robert Cummings rob...@interjinn.com wrote: Peter Lind wrote: This is one example where references actually decrease memory usage. The main reason is the recursive nature of the function. Try BTW, it's not the recursive nature of the function causing the problem. It's the movement of the internal pointer within the array. When it moves the COW realizes the copy's pointer has moved and splits off the copy. You can verify this by echoing the memory usage when you first enter carray(). The spike occurs inside the foreach loop. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] web sniffer
You should be able to do that by setting context options: http://www.php.net/manual/en/context.http.php On 19 March 2010 08:53, Jochen Schultz jschu...@sportimport.de wrote: Btw., when you use file_get_contets, is there a good way to tell the script to stop recieving the file after let's say 2 seconds - just in case the server is not reachable - to avoid using fsockopen? regards Jochen madunix schrieb: okay ..it works now i use ?php $data=file_get_contents(http://www.my.com;); echo $data; ? On Fri, Mar 19, 2010 at 12:32 AM, Adam Richardson simples...@gmail.com wrote: On Thu, Mar 18, 2010 at 6:08 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-03-19 at 00:11 +0200, madunix wrote: trying http://us3.php.net/manual/en/function.fsockopen.php do you a piece of code that read parts pages. On Fri, Mar 19, 2010 at 12:00 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-03-19 at 00:03 +0200, madunix wrote: I've been trying to read the contents from a particular URL into a string in PHP, and can't get it to work. any help. Thanks -- If there is a way, I will find one...*** If there is none, I will make one...*** madunix ** How have you been trying to do it so far? There are a couple of ways. file_get_contents() and fopen() will work on URL's if the right ports are open. Most usually though cURL is used for this sort of thing. Thanks, Ash http://www.ashleysheridan.co.uk -- If there is a way, I will find one...*** If there is none, I will make one...*** madunix ** I think you're over-complicating things by using fsockopen(). Try one of the functions I mentioned in my last email Thanks, Ash http://www.ashleysheridan.co.uk I agree with Ashley, use one of the other options and then parse the response to get the part of the page you'd like to work with. -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com -- Sport Import GmbH - Amtsgericht Oldenburg - Tel: +49-4405-9280-63 Industriestrasse 39 - HRB 1202900 - 26188 Edewecht - GF: Michael Müllmann -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP in HTML code
On 19 March 2010 10:17, Michael A. Peters mpet...@mac.com wrote: I don't care what people do in their code. I do not like released code with short tags, it has caused me problems when trying to run php webapps that use short tags, I have to go through the code and change them. So what people do with their private code, I could care less about. But if releasing php code for public consumption, I guess I'm a preacher asking people to get religion, because short tags do not belong in projects that are released to the public. Just like addslashes and magic quotes and most html entities should not be used in php code released for public consumption. What he said. Now, could we get over this discussion? It's not exactly going anywhere. -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no svn checkout of the current PHP development repo?
You should probably have a look at the internals list - there's a lot of discussion going on as to what should happen in terms of SVN structure. Regards Peter On 20 March 2010 12:32, Robert P. J. Day rpj...@crashcourse.ca wrote: just for fun, i figured i'd check out the current PHP development stream. however, if you read the web page here: http://php.net/svn.php there's no mention of the trunk, simply references to branches such as 5.2 and 5.3. i popped over to: http://svn.php.net/viewvc/php/php-src/ and, sure enough, there's no trunk directory. am i just missing something? because if i click on the PHP 6 link up there on the right (which represents exactly what i'd expect for the URL of the trunk), bad things happen: An Exception Has Occurred Unknown location: /php/php-src/trunk HTTP Response Status 404 Not Found thoughts? i'll assume this is just a temporary thing but, in any event, if the trunk is normally available, the PHP svn page should really mention it explicitly, not just the 5.x branches. rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Filtering all output to STDERR
You could consider suppressing errors for the duration of the problematic call - if indeed you're looking at a warning that doesn't grind everything to a halt. On 22 March 2010 18:01, Marten Lehmann lehm...@cnm.de wrote: Hello, we have a strange problem here: - Our ISP is merging STDERR and STDOUT to STDOUT - We are calling a non-builtin function within PHP 5.2 which includes a lot of code and calls a lot of other functions - When calling this function, we receive the output Cannot open on STDERR. But since STDERR and STDOUT are merged, this Cannot open breaks the required HTTP-header which needs to be sent first. We really tried a lot to find out where this message comes from, we even used strace and ran PHP on the command line. But we cannot figure out the origin, so all we want to do is to get rid of the output sent to STDERR. We tried to close STDERR, but it didn't work out. We thought of using ob_start() and ob_end_clean(), but we cannot get it working with STDERR. Any ideas? Kind regards Marten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Filtering all output to STDERR
Have you tried with http://dk2.php.net/manual/en/function.error-reporting.php or just the @ operator? On 22 March 2010 23:56, Marten Lehmann lehm...@cnm.de wrote: Hello, You could consider suppressing errors for the duration of the problematic call yes, but how? Regards Marten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Filtering all output to STDERR
Ahh, I see why my suggestions had no effect - I assumed you were dealing with normal php errors, not something done customly by the code. I'm afraid the only option I see is that of debugging the problem script to find out where it opens STDERR - if you're certain that the script specifically outputs messages to STDERR, then it's opening that stream somewhere before the output. Regards Peter On 23 March 2010 11:28, Marten Lehmann lehm...@cnm.de wrote: Have you tried with http://dk2.php.net/manual/en/function.error-reporting.php or just the @ operator? Yes. But this does not work, because error levels and the @ operator only relate to errors thrown by the PHP runtime and have nothing to do with STDERR. But I need a way to close the STDERR file handle at the beginning of a script or at least catch and remove all output sent to STDERR. Regards Marten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP to access shell script to print barcodes
You can create a .php script that sets a proper header to make the browser download the file rather than display it. That also allows you to set the filename for the download. What you'd need to do is include something like: header(Content-Disposition: attachment; filename: 'barcodemerge.ps'); That tells the browser to download the file. You can also try setting the content-type header('Content-type: application/postscript'); Either of the above might do the trick for you. Regards Peter On 23 March 2010 22:10, Rob Gould gould...@me.com wrote: I love the idea of using PHP to insert data into Postscript. I'm just not sure how to make it happen. The good news is that I've got barcodes drawing just the way I need them: http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps The bad news is that's all hard-coded Postscript. I'd like to take your suggestion and use PHP to loop-through and draw the barcodes - - - however, if I put anything that resembles PHP in my .ps file, bad things happen. Anyone know the secret to creating a postscript .ps file that had PHP code injecting data into it? Here's the source file that works. Where PHP would be handy is at the very bottom of the script http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps.zip On Mar 23, 2010, at 7:48 AM, Richard Quadling wrote: On 23 March 2010 05:48, Jochem Maas joc...@iamjochem.com wrote: Op 3/23/10 3:27 AM, Rob Gould schreef: I am trying to replicate the functionality that I see on this site: http://blog.maniac.nl/webbased-pdf-lto-barcode-generator/ Notice after you hit SUBMIT QUERY, you get a PDF file with a page of barcodes. That's _exactly_ what I'm after. Fortunately, the author gives step-by-step instructions on how to do this on this page: http://blog.maniac.nl/2008/05/28/creating-lto-barcodes/ So I've gotten through all the steps, and have created the barcode_with_samples.ps file, and have it hosted here: http://www.winecarepro.com/kiosk/fast/shell/ Notice how the last few lines contain the shell-script that renders the postscript: #!/bin/bash BASE=”100″; NR=$BASE for hor in 30 220 410 do ver=740 while [ $ver -ge 40 ]; do printf -v FNR “(%06dL3)” $NR echo “$hor $ver moveto $FNR (includetext height=0.55) code39 barcode” let ver=$ver-70 let NR=NR+1 done done I need to somehow create a PHP script that executes this shell script. And after doing some research, it sounds like I need to use the PHP exec command, so I do that with the following file: http://www.winecarepro.com/kiosk/fast/shell/printbarcodes.php Which has the following script: ?php $command=http://www.winecarepro.com/kiosk/fast/shell/barcode_with_sample.ps;; exec($command, $arr); echo $arr; ? And, as you can see, nothing works. I guess firstly, I'd like to know: A) Is this PHP exec call really the way to go with executing this shell script? Is there a better way? It seems to me like it's not really executing. that's what exec() is for. $command need to contain a *local* path to the command in question, currently your trying to pass a url to bash ... which obviously doesn't do much. the shell script in question needs to have the executable bit set in order to run (either that or change to command to run bash with your script as an argument) I'd also suggest putting the shell script outside of your webroot, or at least in a directory that's not accessable from the web. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I think this is a translation of the script to PHP. ?php $BASE = 100; $NR = $BASE; foreach(array(30, 220, 410) as $hor) { $ver = 740; while ($ver = 40) { printf($hor $ver moveto (%06dL3) (includetext height=0.55) code39 barcode\n, $NR); $ver -= 70; ++$NR; } } It produces output like ... 30 740 moveto (000100L3) (includetext height=0.55) code39 barcode 30 670 moveto (000101L3) (includetext height=0.55) code39 barcode 30 600 moveto (000102L3) (includetext height=0.55) code39 barcode 30 530 moveto (000103L3) (includetext height=0.55) code39 barcode 30 460 moveto (000104L3) (includetext height=0.55) code39 barcode 30 390 moveto (000105L3) (includetext height=0.55) code39 barcode 30 320 moveto (000106L3) (includetext height=0.55) code39 barcode 30 250 moveto (000107L3) (includetext height=0.55) code39 barcode 30 180 moveto (000108L3) (includetext height=0.55) code39 barcode 30 110 moveto (000109L3) (includetext height=0.55) code39 barcode 30 40 moveto (000110L3) (includetext height=0.55) code39 barcode 220 740 moveto (000111L3) (includetext height=0.55) code39 barcode 220 670 moveto (000112L3) (includetext height=0.55) code39 barcode 220 600 moveto (000113L3) (includetext height=0.55) code39 barcode 220 530 moveto (000114L3) (includetext height=0.55) code39 barcode 220 460
Re: [PHP] PHP to access shell script to print barcodes
The problem you're getting is that your web-server interprets the request as a request for a normal file and just sends it - in effect, you're not outputting the postscript file, you're just sending the .php file. Normally, you'll only get your php executed if the file requested is a .php or .phtml - unless you've changed your server config. Try creating a serveps.php that uses the header(Content-Disposition: attachment; filename: 'serveps.ps') instead, see if that helps you. Regards On 24 March 2010 06:09, Rob Gould gould...@me.com wrote: Well, that did something, and it does sound like it should work. I've scoured the web and haven't found anyone with code that does what I'm trying to do. I've got a working, hardcoded Postscript file here: http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps But I need to somehow serve it with PHP, so I can change some variables in it. By putting headers in place with PHP, and then doing an echo of the postscript, I get postscript errors (though Preview doesn't tell me what the error is): http://www.winecarepro.com/kiosk/fast/shell/serverps.ps Trying to trick the web-browser into thinking it's receiving Postscript from a PHP file is tricky. I don't know what to do next. Here's the code I was using in the above url: http://www.winecarepro.com/kiosk/fast/shell/serveps.php.zip It's not clear to me if the server is parsing the postscript first and then serving it, or if the server is server the postscript as-is and the browser sends it to Preview which interprets it. I basically want to replicate the functionality found here: http://blog.maniac.nl/webbased-pdf-lto-barcode-generator/ On Mar 23, 2010, at 5:37 PM, Peter Lind wrote: You can create a .php script that sets a proper header to make the browser download the file rather than display it. That also allows you to set the filename for the download. What you'd need to do is include something like: header(Content-Disposition: attachment; filename: 'barcodemerge.ps'); That tells the browser to download the file. You can also try setting the content-type header('Content-type: application/postscript'); Either of the above might do the trick for you. Regards Peter On 23 March 2010 22:10, Rob Gould gould...@me.com wrote: I love the idea of using PHP to insert data into Postscript. I'm just not sure how to make it happen. The good news is that I've got barcodes drawing just the way I need them: http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps The bad news is that's all hard-coded Postscript. I'd like to take your suggestion and use PHP to loop-through and draw the barcodes - - - however, if I put anything that resembles PHP in my .ps file, bad things happen. Anyone know the secret to creating a postscript .ps file that had PHP code injecting data into it? Here's the source file that works. Where PHP would be handy is at the very bottom of the script http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps.zip On Mar 23, 2010, at 7:48 AM, Richard Quadling wrote: On 23 March 2010 05:48, Jochem Maas joc...@iamjochem.com wrote: Op 3/23/10 3:27 AM, Rob Gould schreef: I am trying to replicate the functionality that I see on this site: http://blog.maniac.nl/webbased-pdf-lto-barcode-generator/ Notice after you hit SUBMIT QUERY, you get a PDF file with a page of barcodes. That's _exactly_ what I'm after. Fortunately, the author gives step-by-step instructions on how to do this on this page: http://blog.maniac.nl/2008/05/28/creating-lto-barcodes/ So I've gotten through all the steps, and have created the barcode_with_samples.ps file, and have it hosted here: http://www.winecarepro.com/kiosk/fast/shell/ Notice how the last few lines contain the shell-script that renders the postscript: #!/bin/bash BASE=”100″; NR=$BASE for hor in 30 220 410 do ver=740 while [ $ver -ge 40 ]; do printf -v FNR “(%06dL3)” $NR echo “$hor $ver moveto $FNR (includetext height=0.55) code39 barcode” let ver=$ver-70 let NR=NR+1 done done I need to somehow create a PHP script that executes this shell script. And after doing some research, it sounds like I need to use the PHP exec command, so I do that with the following file: http://www.winecarepro.com/kiosk/fast/shell/printbarcodes.php Which has the following script: ?php $command=http://www.winecarepro.com/kiosk/fast/shell/barcode_with_sample.ps;; exec($command, $arr); echo $arr; ? And, as you can see, nothing works. I guess firstly, I'd like to know: A) Is this PHP exec call really the way to go with executing this shell script? Is there a better way? It seems to me like it's not really executing. that's what exec() is for. $command need to contain a *local* path to the command in question, currently your trying to pass a url to bash ... which obviously doesn't do much. the shell script in question needs to have
Re: [PHP] Will PHP ever grow up and have threading?
On 24 March 2010 10:38, Rene Veerman rene7...@gmail.com wrote: and if threading and shared memory aren't implemented, then hey, the php dev team can build something else in that these naysayers DO need eh... lol... Do you have any idea how sad and pathetic you come across? I'm very sorry to say this, but really, now's the time to stop posting and step back, take a deep breath, then focus on something else. On Wed, Mar 24, 2010 at 11:36 AM, Rene Veerman rene7...@gmail.com wrote: unless the actual php development team would like to weigh in on this matter of course. yes, i do consider it that important. these nay-sayers usually also lobby the dev-team to such extent that these features would actually not make it into php. On Wed, Mar 24, 2010 at 11:31 AM, Rene Veerman rene7...@gmail.com wrote: php is not a hammer, its a programming language. one that i feel needs to stay ahead of the computing trend if it is to be considered a language for large scale applications. but you nay-sayers here have convinced me; i'll be shopping for another language with which to serve my applications and the weboutput they produce.. thanks for opening my eyes and telling to abandon ship in time. On Wed, Mar 24, 2010 at 11:22 AM, Stuart Dallas stut...@gmail.com wrote: Heh, you guys are funny! On 24 Mar 2010, at 08:58, Rene Veerman wrote: On Wed, Mar 24, 2010 at 10:47 AM, Per Jessen p...@computer.org wrote: Rene Veerman wrote: popular : facebook youtube etc Rene, I must be missing something here. That sort of size implies millions in advertising revenue, so why are we discussing how much performance we can squeeze out of a single box? I mean, I'm all for efficient use of system resources, but if I have a semi-scalable application, it's a lot easier just getting another box than trying to change the implementation language. OTOH, if my design is not scalable, it's probably also easier to redo it than trying to change the implementation language. again: a) you're determining the contents of my toolset, without it affecting you at all. the way you want it php will degrade into a toy language. And how exactly are you defining a toy language? If you want features like threading, why not switch to a language that already supports it? b) i will aim for all possible decreases in development time and operating costs during, not only in the grow phase but also in hard economic times. any business person knows why. Yup, this is very good practice, but deciding that one particular tool is the only option is a fatal business decision. Use the right tool for the job! What you're trying to do here is akin to taking a hammer and whittling a screwdriver in to the handle. It's ridiculously inefficient, and imo, pretty stupid. and you're still trying to impose a toolset on me. I didn't think I was - you're the one who seem to be fixed on PHP as the only solution, and advocating that it be enhanced to suit your purposes. no, php is just my toolset of choice, and i think it should grow with the times and support threading and shared memory. maybe even a few cool features to enable use-as-a-cloud. PHP is a hammer, and a bloody good one at that, but you seem to want it to be a tool shed. Accept that it's a hammer, go visit a DIY store, find the right tool for the job and get on with your life! The fact is that even if we all agree that PHP needs threading, and one or more people start working on putting it into the core, it will likely be many months before you see any sight of a working version, and even longer before you see a stable release. -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Will PHP ever grow up and have threading?
On 24 March 2010 11:53, Tommy Pham tommy...@gmail.com wrote: On Wed, Mar 24, 2010 at 3:44 AM, Per Jessen p...@computer.org wrote: Tommy Pham wrote: On Wed, Mar 24, 2010 at 3:20 AM, Per Jessen p...@computer.org wrote: Tommy Pham wrote: What I find funny is that one of opponents of PHP threads earlier mentioned that how silly it would be to be using C in a web app. Now I hear people mentioning C when they need productivity or speed... I think I was the one to mention the latter, but as I started out saying, and as others have said too, it's about the right tool for the right job. When choosing a tool, there are a number of factors to consider - developer productivity, available skills, future maintenance, performance, scalability, portability, parallelism, performance etcetera. Funny you should mention all that. Let's say that you're longer with that company, either by direct employment or contract consultant. You've implemented C because you need 'thread'. Now your replacement comes in and has no clue about C even though your replacement is a PHP guru. How much headache is maintenance gonna be? Scalability? Portability? wow Who was the idi... who hired someone who wasn't suited for the job? Tommy, that's a moot argument. You can't fit a square peg in a round hole. -- Per Jessen, Zürich (12.5°C) Suited for the job? You mean introduce more complexity to a problem that what could be avoided to begin with if PHP has thread support? hmmm Except, you already introduced complexity into the problem. You see, working with threads is another requirement, whether it be done in PHP or not. Hence, hiring the right guy is independent of whether you have threads in PHP or not - your problem is no less nor no more complex whether you do threading inside or outside PHP. You just assume that adding thread support to PHP will solve the problem, but there's no actual basis to believe this. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Will PHP ever grow up and have threading?
On 24 March 2010 12:04, Tommy Pham tommy...@gmail.com wrote: On Wed, Mar 24, 2010 at 3:52 AM, Lester Caine les...@lsces.co.uk wrote: Tommy Pham wrote: How exactly will threading in PHP help with the size of the database? That makes no sense to me, please help me understand how you think threading will help in this scenario. Looking at my example, not just the rows There are other features that require queries to a DB for simple request of a category by a shopper, instead of running those queries in series, running them in parallel would yield better response time. Database size issues are tackled with clustering, caching and DB optimisation. Threading in the language accessing the DB has no advantage here. Yes, it does. As mentioned several times, instead of running the queries in series, run them in parallel. If each of the queries takes about .05 to .15 seconds. How long would it take to run them in serial? How long do you it take to run them in parallel? Any you have a database that can actually handle that? If the database is taking 0.1 seconds per query, and you have 10 queries, then getting the data is going to take 1 second to generate. If you want some slow query to be started, and come back for the data later, then I thought we already had that? But again this is part of the database driver anyway. No need to add threading to PHP to get the database connection to pull data in the most efficient way. And one does not write the driver in PHP? We are using C there already? -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Exactly my point. 10 queries taking .1 second each running in serial is 1 second total. How long would it take to run all those same queries simultaneously??? What's so difficult about the concept of serial vs parallel? Hmm, just wondering, but how long do you think it will take your high-traffic site to buckle under the load of the database queries you want to execute when now you want all of them to execute at the same time? Going with the 10 queries of .1 second each ... how far do you think you can scale that before you overload your database server? I'm just wondering here, I could be completely off the bat. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Will PHP ever grow up and have threading?
On 24 March 2010 12:14, Tommy Pham tommy...@gmail.com wrote: On Wed, Mar 24, 2010 at 4:09 AM, Peter Lind peter.e.l...@gmail.com wrote: On 24 March 2010 12:04, Tommy Pham tommy...@gmail.com wrote: On Wed, Mar 24, 2010 at 3:52 AM, Lester Caine les...@lsces.co.uk wrote: Tommy Pham wrote: How exactly will threading in PHP help with the size of the database? That makes no sense to me, please help me understand how you think threading will help in this scenario. Looking at my example, not just the rows There are other features that require queries to a DB for simple request of a category by a shopper, instead of running those queries in series, running them in parallel would yield better response time. Database size issues are tackled with clustering, caching and DB optimisation. Threading in the language accessing the DB has no advantage here. Yes, it does. As mentioned several times, instead of running the queries in series, run them in parallel. If each of the queries takes about .05 to .15 seconds. How long would it take to run them in serial? How long do you it take to run them in parallel? Any you have a database that can actually handle that? If the database is taking 0.1 seconds per query, and you have 10 queries, then getting the data is going to take 1 second to generate. If you want some slow query to be started, and come back for the data later, then I thought we already had that? But again this is part of the database driver anyway. No need to add threading to PHP to get the database connection to pull data in the most efficient way. And one does not write the driver in PHP? We are using C there already? -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Exactly my point. 10 queries taking .1 second each running in serial is 1 second total. How long would it take to run all those same queries simultaneously??? What's so difficult about the concept of serial vs parallel? Hmm, just wondering, but how long do you think it will take your high-traffic site to buckle under the load of the database queries you want to execute when now you want all of them to execute at the same time? Going with the 10 queries of .1 second each ... how far do you think you can scale that before you overload your database server? I'm just wondering here, I could be completely off the bat. IIRC, one of opponents of PHP thread mention load balancer/cluster or another opponent mention 'throw money into the hardware problem' Yes. If you can accept that solution for this problem, why not for the other problem? Please keep in mind that I'm not for or against threads in PHP. I think they can solve some problems and I think they'll create a host of others - currently I have no idea if the benefits would outweigh the costs. I just have a huge problem understanding why alternative solutions to problems are thrown out with No! That won't work when they haven't been shown to be problematic. So far, we've seen no examples of situations where PHP would be the best choice of language and would need threads to solve the problem at hand. Assuming that you have a right to use a threaded version of PHP amounts to walking into your favourite tool-store and demanding that you get a hammer that doubles as a phone. And when none are available, you start yelling at other customers for suggesting the use of a phone and hammer in combination. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Properly handling multiple constructors.
Hmmm, that looks to me like you're trying to solve a problem in PHP with a c/c++c/# overloading solution. I'd give the builder pattern a try instead: http://en.wikipedia.org/wiki/Builder_pattern On 24 March 2010 13:01, Richard Quadling rquadl...@googlemail.com wrote: Hi. I have a scenario where I would _like_ to have multiple constructors for a class. Each constructor has a greater number of parameters than the previous one. e.g. ?php class myClass { __construct(string $Key) // use key to get the complex details. __construct(string $Part1, string $Part2, string $Part3) // Alternative route to the complex details. __construct(array $Complex) // All the details } Essentially, SimpleKey is a key to a set of predefined rules. Part1, 2 and 3 are the main details and well documented defaults for the rest of the rules. Complex is all the rules. Each constructor will end up with all the parts being known ($Key, $Part1, $Part2, $Part3, $Complex). But, PHP doesn't support multiple constructors. Initially I thought about this ... __construct($Key_Part1_Complex, $Part2=Null, $Part3=Null) But then documenting the first param as being 1 of three different meanings is pretty much a no go. So I'm looking for a clean and easily understood way to provide this. I won't be the only user of the code and not everyone has the same knowledge level, hence a mechanism that is easily documentable. I think I may need a factory with multiple methods (FactoryKey, FactoryPart1To3, FactoryComplex). Make the factory a static/singleton. All these methods eventually call the real class with the complex rule. Is that obvious enough? Regards, Richard. -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Properly handling multiple constructors.
And how exactly does that differ from building the same pizza in different ways? Builder doesn't mean you have to create different objects, it means taking the complexity in building a given object or set of objects and storing it in one place. In your case, it allows you to build your object in different ways while documenting it properly and avoid the huge switch inside your constructor that Nilesh proposed. On 24 March 2010 13:35, Richard Quadling rquadl...@googlemail.com wrote: On 24 March 2010 12:06, Peter Lind peter.e.l...@gmail.com wrote: Hmmm, that looks to me like you're trying to solve a problem in PHP with a c/c++c/# overloading solution. I'd give the builder pattern a try instead: http://en.wikipedia.org/wiki/Builder_pattern On 24 March 2010 13:01, Richard Quadling rquadl...@googlemail.com wrote: Hi. I have a scenario where I would _like_ to have multiple constructors for a class. Each constructor has a greater number of parameters than the previous one. e.g. ?php class myClass { __construct(string $Key) // use key to get the complex details. __construct(string $Part1, string $Part2, string $Part3) // Alternative route to the complex details. __construct(array $Complex) // All the details } Essentially, SimpleKey is a key to a set of predefined rules. Part1, 2 and 3 are the main details and well documented defaults for the rest of the rules. Complex is all the rules. Each constructor will end up with all the parts being known ($Key, $Part1, $Part2, $Part3, $Complex). But, PHP doesn't support multiple constructors. Initially I thought about this ... __construct($Key_Part1_Complex, $Part2=Null, $Part3=Null) But then documenting the first param as being 1 of three different meanings is pretty much a no go. So I'm looking for a clean and easily understood way to provide this. I won't be the only user of the code and not everyone has the same knowledge level, hence a mechanism that is easily documentable. I think I may need a factory with multiple methods (FactoryKey, FactoryPart1To3, FactoryComplex). Make the factory a static/singleton. All these methods eventually call the real class with the complex rule. Is that obvious enough? Regards, Richard. -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype I'm not building different types of pizza. Just the same pizza via different routes. Along the lines of ... Pizza = new Pizza('MyFavouritePizza') // A ham+pineapple+cheese pizza. Pizza = new Pizza('ham', 'pineapple', 'cheese'); // A generic ham+pineapple+cheese pizza Pizza = new Pizza(array('base' = 'thin', 'toppings' = array('ham', 'pineapple'), 'cheese'=true)); // A complex description. I suppose the interfaces are beginner, intermediate and advanced, but ultimately all generate identical objects. Richard. -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Properly handling multiple constructors.
One of the main points of the OP was that you can document the code properly. Your example doesn't allow for nice docblocks in any way, as you'll either have to param points or a whole lot of noise. Quick note: __ prefixed functions are reserved, you shouldn't use that prefix for any of your own functions. However unlikely it is that PHP will ever have a __construct_bluh() function ... On 24 March 2010 15:22, Robert Cummings rob...@interjinn.com wrote: Robert Cummings wrote: Richard Quadling wrote: Hi. I have a scenario where I would _like_ to have multiple constructors for a class. Each constructor has a greater number of parameters than the previous one. e.g. ?php class myClass { __construct(string $Key) // use key to get the complex details. __construct(string $Part1, string $Part2, string $Part3) // Alternative route to the complex details. __construct(array $Complex) // All the details } Essentially, SimpleKey is a key to a set of predefined rules. Part1, 2 and 3 are the main details and well documented defaults for the rest of the rules. Complex is all the rules. Each constructor will end up with all the parts being known ($Key, $Part1, $Part2, $Part3, $Complex). But, PHP doesn't support multiple constructors. Initially I thought about this ... __construct($Key_Part1_Complex, $Part2=Null, $Part3=Null) But then documenting the first param as being 1 of three different meanings is pretty much a no go. So I'm looking for a clean and easily understood way to provide this. I won't be the only user of the code and not everyone has the same knowledge level, hence a mechanism that is easily documentable. I think I may need a factory with multiple methods (FactoryKey, FactoryPart1To3, FactoryComplex). Make the factory a static/singleton. All these methods eventually call the real class with the complex rule. Is that obvious enough? Factory method is probably the cleanest and simplest solution. Just pass an ID as the first parameter to the real constructor and then it can route to the appropriate behaviour: Here's a better example (tested): ?php class Foo { const CONSTRUCT_BLAH = 1; const CONSTRUCT_BLEH = 2; const CONSTRUCT_BLUH = 3; function __construct( $constructId ) { static $map = array ( self::CONSTRUCT_BLAH = '__construct_blah', self::CONSTRUCT_BLEH = '__construct_bleh', self::CONSTRUCT_BLUH = '__construct_bluh', ); $obj = null; if( isset( $map[$constructId] ) ) { $args = func_get_args(); $args = array_shift( $args ); call_user_func_array( array( 'self', $map[$constructId] ), $args ); } else { // Generate an error or exception. } } static function __construct_bleh( $arg1 ) { echo Called: .__FUNCTION__.( $arg1 )\n; } static function __construct_blah( $arg1 ) { echo Called: .__FUNCTION__.( $arg1 )\n; } static function __construct_bluh( $arg1 ) { echo Called: .__FUNCTION__.( $arg1 )\n; } static function getBlah( $arg1 ) { return new Foo( self::CONSTRUCT_BLAH, $arg1 ); } static function getBleh( $arg1 ) { return new Foo( self::CONSTRUCT_BLEH, $arg1 ); } static function getBluh( $arg1 ) { return new Foo( self::CONSTRUCT_BLUH, $arg1 ); } } $obj = Foo::getBlah( 'blah' ); $obj = Foo::getBleh( 'bleh' ); $obj = Foo::getBluh( 'bluh' ); ? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Properly handling multiple constructors.
On 24 March 2010 15:33, Robert Cummings rob...@interjinn.com wrote: Peter Lind wrote: One of the main points of the OP was that you can document the code properly. Your example doesn't allow for nice docblocks in any way, as you'll either have to param points or a whole lot of noise. I dunno, seems highly documentable to me. Each route is handled by it's own method with the parameters being fully declared in the handler method's signature. Only problem is the OP wanted to be able to created objects with variable amounts of arguments. I.e. passing just one argument to the constructor wasn't an option, far as I could tell. That's why he was looking at c++/c# overloading: creating a constructor for each scenario because the amount and kind of arguments varied. Which means that the docblock for your constructor will look something like /** * dynamic constructor * * @param int $constructor_type * @param string|array|object|whatever_you_could_think_to_throw_at_it $something * @param string|array|object|whatever_you_could_think_to_throw_at_it $something this is optional * @param etc * * @access public * @return void */ Quick note: __ prefixed functions are reserved, you shouldn't use that prefix for any of your own functions. However unlikely it is that PHP will ever have a __construct_bluh() function ... Yeah, I know... I threw caution to the wind in this quick example. But for the sake of archives and newbies reading them, I shouldn't have :) Cheers, Rob. On 24 March 2010 15:22, Robert Cummings rob...@interjinn.com wrote: Robert Cummings wrote: Richard Quadling wrote: Hi. I have a scenario where I would _like_ to have multiple constructors for a class. Each constructor has a greater number of parameters than the previous one. e.g. ?php class myClass { __construct(string $Key) // use key to get the complex details. __construct(string $Part1, string $Part2, string $Part3) // Alternative route to the complex details. __construct(array $Complex) // All the details } Essentially, SimpleKey is a key to a set of predefined rules. Part1, 2 and 3 are the main details and well documented defaults for the rest of the rules. Complex is all the rules. Each constructor will end up with all the parts being known ($Key, $Part1, $Part2, $Part3, $Complex). But, PHP doesn't support multiple constructors. Initially I thought about this ... __construct($Key_Part1_Complex, $Part2=Null, $Part3=Null) But then documenting the first param as being 1 of three different meanings is pretty much a no go. So I'm looking for a clean and easily understood way to provide this. I won't be the only user of the code and not everyone has the same knowledge level, hence a mechanism that is easily documentable. I think I may need a factory with multiple methods (FactoryKey, FactoryPart1To3, FactoryComplex). Make the factory a static/singleton. All these methods eventually call the real class with the complex rule. Is that obvious enough? Factory method is probably the cleanest and simplest solution. Just pass an ID as the first parameter to the real constructor and then it can route to the appropriate behaviour: Here's a better example (tested): ?php class Foo { const CONSTRUCT_BLAH = 1; const CONSTRUCT_BLEH = 2; const CONSTRUCT_BLUH = 3; function __construct( $constructId ) { static $map = array ( self::CONSTRUCT_BLAH = '__construct_blah', self::CONSTRUCT_BLEH = '__construct_bleh', self::CONSTRUCT_BLUH = '__construct_bluh', ); $obj = null; if( isset( $map[$constructId] ) ) { $args = func_get_args(); $args = array_shift( $args ); call_user_func_array( array( 'self', $map[$constructId] ), $args ); } else { // Generate an error or exception. } } static function __construct_bleh( $arg1 ) { echo Called: .__FUNCTION__.( $arg1 )\n; } static function __construct_blah( $arg1 ) { echo Called: .__FUNCTION__.( $arg1 )\n; } static function __construct_bluh( $arg1 ) { echo Called: .__FUNCTION__.( $arg1 )\n; } static function getBlah( $arg1 ) { return new Foo( self::CONSTRUCT_BLAH, $arg1 ); } static function getBleh( $arg1 ) { return new Foo( self::CONSTRUCT_BLEH, $arg1 ); } static function getBluh( $arg1 ) { return new Foo( self::CONSTRUCT_BLUH, $arg1 ); } } $obj = Foo::getBlah( 'blah' ); $obj = Foo::getBleh( 'bleh' ); $obj = Foo::getBluh( 'bluh' ); ? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- http://www.interjinn.com Application and Templating Framework for PHP -- hype WWW: http://plphp.dk / http://plind.dk
Re: [PHP] Properly handling multiple constructors.
On 24 March 2010 16:09, Robert Cummings rob...@interjinn.com wrote: Peter Lind wrote: On 24 March 2010 15:33, Robert Cummings rob...@interjinn.com wrote: Peter Lind wrote: One of the main points of the OP was that you can document the code properly. Your example doesn't allow for nice docblocks in any way, as you'll either have to param points or a whole lot of noise. I dunno, seems highly documentable to me. Each route is handled by it's own method with the parameters being fully declared in the handler method's signature. Only problem is the OP wanted to be able to created objects with variable amounts of arguments. I.e. passing just one argument to the constructor wasn't an option, far as I could tell. That's why he was looking at c++/c# overloading: creating a constructor for each scenario because the amount and kind of arguments varied. Which means that the docblock for your constructor will look something like /** * dynamic constructor * * @param int $constructor_type * @param string|array|object|whatever_you_could_think_to_throw_at_it $something * @param string|array|object|whatever_you_could_think_to_throw_at_it $something this is optional * @param etc * * @access public * @return void */ Actually, I would write it more like the following: /** * dynamic constructor that delegates construction and parameters to a * registered alternate constructor. See specific constructors for * supported parameters. * * @param int $constructor_type * @param mixed $param, * * @access public * @return void */ The ,... is a supported syntax. Then I'd add the appropriate docblock for the alternate constructors. It might be but in effect the documentation you're left with is vague and has double the amount of documentation lookups, to find out which parameters you can pass. Using a separate object to create the one you want avoids this. However, which solution fits the problem best is determined by the angle you're looking from. If you want to avoid extra classes, having a constructor like you're supposing is probably the best idea. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Properly handling multiple constructors.
On 24 March 2010 16:23, Robert Cummings rob...@interjinn.com wrote: Peter Lind wrote: On 24 March 2010 16:09, Robert Cummings rob...@interjinn.com wrote: Peter Lind wrote: On 24 March 2010 15:33, Robert Cummings rob...@interjinn.com wrote: Peter Lind wrote: One of the main points of the OP was that you can document the code properly. Your example doesn't allow for nice docblocks in any way, as you'll either have to param points or a whole lot of noise. I dunno, seems highly documentable to me. Each route is handled by it's own method with the parameters being fully declared in the handler method's signature. Only problem is the OP wanted to be able to created objects with variable amounts of arguments. I.e. passing just one argument to the constructor wasn't an option, far as I could tell. That's why he was looking at c++/c# overloading: creating a constructor for each scenario because the amount and kind of arguments varied. Which means that the docblock for your constructor will look something like /** * dynamic constructor * * @param int $constructor_type * @param string|array|object|whatever_you_could_think_to_throw_at_it $something * @param string|array|object|whatever_you_could_think_to_throw_at_it $something this is optional * @param etc * * @access public * @return void */ Actually, I would write it more like the following: /** * dynamic constructor that delegates construction and parameters to a * registered alternate constructor. See specific constructors for * supported parameters. * * @param int $constructor_type * @param mixed $param, * * @access public * @return void */ The ,... is a supported syntax. Then I'd add the appropriate docblock for the alternate constructors. It might be but in effect the documentation you're left with is vague and has double the amount of documentation lookups, to find out which parameters you can pass. Using a separate object to create the one you want avoids this. But then you need to keep track of many different classes/objects rather than a single. You also run into confusion as to what the difference is when really they are the same, just built differently. In this context you have even more document points to review since you must read the class information in addition to the method signature. Also using a separate class just to facilitate a different constructor seems abusive of class semantics since the objects are intended to be identical, just built differently. I would find this more unwieldy to deal with in an environement than just viewing the alternate methods. Yes, you have to keep track of two different objects instead of one. Managing complexity by delegating responsibility is normally a good thing. And no, there is no confusion: you're building the same object in different ways, so you're getting the same object, not one that merely looks the same. As for abusing class semantics ... I don't see it. Using separate classes for different things is what OOP is about. If your constructor is trying to do 15 different things you're designing it wrong - methods shouldn't have to rely upon massive switches or the equivalent done using foreach loops and arrays. As for more documentation: You'd have two class docblocks plus a docblock for each build method, so I suppose you're right, that is one extra docblock. However, which solution fits the problem best is determined by the angle you're looking from. If you want to avoid extra classes, having a constructor like you're supposing is probably the best idea. Extra classes is also more code, probably more files (if you put them in separate files), more points of management. Yes. What does your code look like? One big file containing everything? Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Properly handling multiple constructors.
On 24 March 2010 16:48, Robert Cummings rob...@interjinn.com wrote: Peter Lind wrote: The ,... is a supported syntax. Then I'd add the appropriate docblock for the alternate constructors. It might be but in effect the documentation you're left with is vague and has double the amount of documentation lookups, to find out which parameters you can pass. Using a separate object to create the one you want avoids this. But then you need to keep track of many different classes/objects rather than a single. You also run into confusion as to what the difference is when really they are the same, just built differently. In this context you have even more document points to review since you must read the class information in addition to the method signature. Also using a separate class just to facilitate a different constructor seems abusive of class semantics since the objects are intended to be identical, just built differently. I would find this more unwieldy to deal with in an environement than just viewing the alternate methods. Yes, you have to keep track of two different objects instead of one. Managing complexity by delegating responsibility is normally a good thing. Absolutely, delegating responsibility to manage complexity is very good. My proposed solution does this. And no, there is no confusion: you're building the same object in different ways, so you're getting the same object, not one that merely looks the same. No, you're getting different objects. If they come from different classes then they are different. Yes they may be subclasses, but the OP indicated they differ only by how they are built. Adding 10 different subclasses just to facilitate constructor overloading seems egregious, especially if the object already has logical subclasses. As I suspected, you didn't understand what I meant. The builder pattern lets you build complex objects in steps, separating out complexity. It's equally well suited to building one object as many objects and what I had in mind was a simplified builder/factory. Which means you have: class ObjectBuilder class Object where ObjectBuilder comes with several different ways of building Object. That's two objects, not the list of objects extending something you posted. class Dog class Dog_construct1 extends Dog class Dog_construct2 extends Dog class Dog_construct3 extends Dog class Dog_construct4 extends Dog class Dalmation extends Dog class Dalmation_construct1 extends Dog_construct1 class Dalmation_construct2 extends Dog_construct2 class Dalmation_construct3 extends Dog_construct3 class Dalmation_construct4 extends Dog_construct4 But now Dalmation_construct1 isn't related to Dalmation... or do you propose the following: class Dalmation extends Dalmation class Dalmation_construct1 extends Dalmation class Dalmation_construct2 extends Dalmation class Dalmation_construct3 extends Dalmation class Dalmation_construct4 extends Dalmation But now Dalmation_construct1 isn't related Dog_construct1. This seems problematic from a design perspective unless I'm missing something in your proposal. As for abusing class semantics ... I don't see it. Using separate classes for different things is what OOP is about. If your constructor is trying to do 15 different things you're designing it wrong - methods shouldn't have to rely upon massive switches or the equivalent done using foreach loops and arrays. Sorry, switches, foreach, and isset are not equivalent. My approach is O( lg n ). Foreach and switches are O( n ) to find a candidate. Additionally, my constructor does 1 thing, it delegates to the appropriate constructor which does one thing also... builds the object according to intent. Yes, your constructor does one thing, which is indirectly related to constructing instead of carrying out the actual constructing. I prefer constructors to construct something, but that's a matter of preference I expect. As for more documentation: You'd have two class docblocks plus a docblock for each build method, so I suppose you're right, that is one extra docblock. However, which solution fits the problem best is determined by the angle you're looking from. If you want to avoid extra classes, having a constructor like you're supposing is probably the best idea. Extra classes is also more code, probably more files (if you put them in separate files), more points of management. Yes. What does your code look like? One big file containing everything? No, I said probably because I put classes in separate files. I was saying there is probably another added maintenance headache of all these new class files. There would be if one were to use your scheme of subclassing. What I proposed doesn't do that in any way, so there's not much of a maintenance headache. Anyway, all this is theoretical seeing as you can equally well use a set of static methods
Re: [PHP] Will PHP ever grow up and have threading?
On 25 March 2010 19:37, Tommy Pham tommy...@gmail.com wrote: On Thu, Mar 25, 2010 at 3:55 AM, Per Jessen p...@computer.org wrote: Tommy Pham wrote: On Thu, Mar 25, 2010 at 1:46 AM, Per Jessen p...@computer.org wrote: * If you could implement threads and run those same queries in 2+ threads, the total time saved from queries execution is 1/2 sec or more, which is pass along as the total response time reduced. Is it worth it for you implement threads if you're a speed freak? Use mysqlnd - asynchronous mysql queries. You're assuming that everyone in the PHP world uses MySQL 4.1 or newer. What about those who don't? They don't get to use threading, nor asynchronous mysql queries. Come on, you're asking about a future feature in PHP 7.x , but would like to support someone who is seriously backlevel on mysql?? -- Per Jessen, Zürich (16.9°C) I'm not talking about MySQL 4.0 or older. I'm talking about other RDBMS. I think you should open your eyes a bit wider and take a look at the bigger picture (Firebird, MSSQL, Oracle, PostgreSQL, etc). http://www.php.net/manual/en/function.pg-send-query.php Looks to me like the PHP postgresql library already handles that. Not to mention: you're not presenting an argument for threads, you're presenting an argument for implementing asynchronous queries in the other DBMS libraries. Of course, the problem could also be solved by introducing threads in PHP. I'd personally guess modifying DBMS libraries would be less costly, but as I haven't been involved in writing the PHP code my guess isn't worth much. Regards Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Will PHP ever grow up and have threading?
On 25 March 2010 20:09, Tommy Pham tommy...@gmail.com wrote: On Thu, Mar 25, 2010 at 12:02 PM, Peter Lind peter.e.l...@gmail.com wrote: On 25 March 2010 19:37, Tommy Pham tommy...@gmail.com wrote: On Thu, Mar 25, 2010 at 3:55 AM, Per Jessen p...@computer.org wrote: Tommy Pham wrote: On Thu, Mar 25, 2010 at 1:46 AM, Per Jessen p...@computer.org wrote: * If you could implement threads and run those same queries in 2+ threads, the total time saved from queries execution is 1/2 sec or more, which is pass along as the total response time reduced. Is it worth it for you implement threads if you're a speed freak? Use mysqlnd - asynchronous mysql queries. You're assuming that everyone in the PHP world uses MySQL 4.1 or newer. What about those who don't? They don't get to use threading, nor asynchronous mysql queries. Come on, you're asking about a future feature in PHP 7.x , but would like to support someone who is seriously backlevel on mysql?? -- Per Jessen, Zürich (16.9°C) I'm not talking about MySQL 4.0 or older. I'm talking about other RDBMS. I think you should open your eyes a bit wider and take a look at the bigger picture (Firebird, MSSQL, Oracle, PostgreSQL, etc). http://www.php.net/manual/en/function.pg-send-query.php Looks to me like the PHP postgresql library already handles that. Not to mention: you're not presenting an argument for threads, you're presenting an argument for implementing asynchronous queries in the other DBMS libraries. Of course, the problem could also be solved by introducing threads in PHP. I'd personally guess modifying DBMS libraries would be less costly, but as I haven't been involved in writing the PHP code my guess isn't worth much. Regards Peter I'm presenting the argument for threading. Per is presenting the work around using asynchronous queries via mysqlnd. I did read that link a few days ago, Although the user can send multiple queries at once, multiple queries cannot be sent over a busy connection. If a query is sent while the connection is busy, it waits until the last query is finished and discards all its results. Which sounds like threads - multiple connections to not run into that problem. Have you looked into what it would cost in development to improve the library? Have you compared that to the cost in development to introduce threads into PHP? No, I don't think you're presenting the argument for threading - but I don't expect you to see it that way. -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Will PHP ever grow up and have threading?
On 25 March 2010 20:19, Tommy Pham tommy...@gmail.com wrote: Aren't all feature requests must be analyzed the same way? Example, namespace, how many of us actually uses it now when there is an alternative solution- subfolders - that we've been using since who knows how long. I don't know if threads was asked a feature prior namespace was implemented. Yes, you're right. But feature requests are not equal: some present a bigger payoff than others, and some will be more problematic to implement than others. If a given language can solve the problems it meets based on it's current structure, should you necessarily implement new shiny features, that may present problems? I'm not against threads in PHP per se ... I just haven't seen a very convincing reason for them yet, which is why I'm not very positive about the thing. The DB scenario could be handled without threads and current libraries could be improved ... and as long as that's cheaper than implementing threads, then - personally - I'd need to see more powerful reasons for threads. Luckily, I have no say in the development of PHP, so I won't get in anyone's way should they choose to implement threads :) -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Will PHP ever grow up and have threading?
On 25 March 2010 20:59, Tommy Pham tommy...@gmail.com wrote: On Thu, Mar 25, 2010 at 12:28 PM, Peter Lind peter.e.l...@gmail.com wrote: On 25 March 2010 20:19, Tommy Pham tommy...@gmail.com wrote: Aren't all feature requests must be analyzed the same way? Example, namespace, how many of us actually uses it now when there is an alternative solution- subfolders - that we've been using since who knows how long. I don't know if threads was asked a feature prior namespace was implemented. Yes, you're right. But feature requests are not equal: some present a bigger payoff than others, and some will be more problematic to implement than others. If a given language can solve the problems it meets based on it's current structure, should you necessarily implement new shiny features, that may present problems? I'm not against threads in PHP per se ... I just haven't seen a very convincing reason for them yet, which is why I'm not very positive about the thing. The DB scenario could be handled without threads and current libraries could be improved ... and as long as that's cheaper than implementing threads, then - personally - I'd need to see more powerful reasons for threads. Luckily, I have no say in the development of PHP, so I won't get in anyone's way should they choose to implement threads :) Here's my analysis, let's say that you have 1000 requests / second on the web server. Each request has multiqueries which take a total of 1 second to complete. In that one second, how many of those 1000 arrive at the same time (that one instant of micro/nano second)? You see how threads come in? If you have threads that are able finish the requests that come in that instant and able to complete them before the next batch of requests in that same second, wouldn't you agree then that you're delivering faster response time to all your users? That sounds like your webserver spawning new processes dealing with requests ... possibly combined with connection pooling and asynchronous queries and load balancing, etc, etc. So no, I'm not convinced that PHP with threads would actually deliver much faster than a properly built setup that makes good usage of technology you'll have to use anyway. -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Will PHP ever grow up and have threading?
On 25 March 2010 22:51, Lester Caine les...@lsces.co.uk wrote: Per Jessen wrote: Tommy Pham wrote: I'm presenting the argument for threading. Per is presenting the work around using asynchronous queries via mysqlnd. I did read that link a few days ago, Although the user can send multiple queries at once, multiple queries cannot be sent over a busy connection. If a query is sent while the connection is busy, it waits until the last query is finished and discards all its results. Which sounds like threads - multiple connections to not run into that problem. You must have read the wrong page. This is NOT about multiple queries, it's about _asynchronous_ queries. The only problem here is what the database client can handle. If it can only handle one active query, then that is all that can be used. It can be started asynchronously and then you come back to pick up the results later, and so you can be formating the page ready to insert the results. PDO requires that you start a different connection in a different transaction for each of these queries, but that is another hot potato. Running 10 asynchronous queries would require 10 connections as that is how the database end works. Adding threading to PHP is going to make no difference? Actually, this sounds very close to having 10 threads each opening a connection to the database and running the query ... which was the solution to the scenario presented, if memory serves. -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Will PHP ever grow up and have threading?
On 25 March 2010 23:23, Tommy Pham tommy...@gmail.com wrote: There's the code example from that same link. You may have executed the queries asynchronously, but the process of the results are still serial. Let's face it, all of our processing of queries are not a simple echo. We iterate/loop through the results and display them in the desired format. Having execute the query and the processing of the result in threads/parallel, you get the real performance boost which I've been trying to convey the concept of serial versus parallel. Actually, you haven't mentioned the processing as part of what the threads do until now. I see your point though: if you split that part off, you might gain some performance, that would otherwise be hard to get at. I wonder though, if the performance is worth it in the tradeoff for the maintenance nightmare it is when you split out content processing between 10 different threads. I wouldn't personally touch it unless I had no other option, but that's just my opinion. Anyway, I don't think either of us will change point of view much at this point - so we should probably just give the mailing list a rest by now. Thanks for the posts, it's been interesting to read :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Allowing multiple, simultaneous, non-blocking queries.
Hi Richard At the end of discussion, the best bet for something that approaches a threaded version of multiple queries would be something like: 1. open connection to database 2. issue query using asynchronous call (mysql and postgresql support this, haven't checked the others) 3. pick up result when ready To get the threaded-ness, just open a connection per query you want to run asynchronous and pick it up when you're ready for it - i.e. iterate over steps 1-2, then do step 3 when things are ready. Regards Peter On 26 March 2010 12:45, Richard Quadling rquadl...@googlemail.com wrote: Hi. As I understand things, one of the main issues in the When will PHP grow up thread was the ability to issue multiple queries in parallel via some sort of threading mechanism. Due to the complete overhaul required of the core and extensions to support userland threading, the general consensus was a big fat No!. As I understand things, it is possible, in userland, to use multiple, non-blocking sockets for file I/O (something I don't seem to be able to achieve on Windows http://bugs.php.net/bug.php?id=47918). Can this process be leveraged to allow for non-blocking queries? Being able to throw out multiple non-blocking queries would allow for the queries in parallel issue. My understanding is that at the base level, all queries are running on a socket in some way, so isn't this facility nearly already there in some way? Regards, Richard. -- - Richard Quadling Standing on the shoulders of some very clever giants! EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: optimizing PHP for microseconds
That's impossible to answer given the brief layout of what you've described. However, rule of thumb: optimizing for microseconds only makes sense when the microseconds together make up a significant amount of time. An example might be in order: for ($i = 0; $i count($stuff); $i++) { // do other stuffs } The above loop is NOT optimal (as most people will tell you) because you'll be doing a count() every loop. However, there's an enormous difference between doing 100 counts and 1.000.000 counts. Microseconds only count when there's enough of them to make up seconds. The best thing to do is adopt the normal good coding standards: don't using functions in loops like the above, for instance. However, be skeptic about tips: single-quotes are not faster than double-quotes, for instance. Regards Peter On 29 March 2010 10:28, Bastien Helders eldroskan...@gmail.com wrote: I have a question as a relatively novice PHP developper. Let's say you have this Intranet web application, that deals with the generation of file bundles that could become quite large (let say in the 800 MB) after some kind of selection process. It should be available to many users on this Intranet, but shouldn't require any installation. Would it be a case where optimizing for microseconds would be recommended? Or would PHP not be the language of choice? I'm not asking to prove that there could be corner case where it could be useful, but I am genuinely interested as I am in the development of such a project, and increasing the performance of this web application is one of my goal. 2010/3/28 Nathan Rixham nrix...@gmail.com mngghh, okay, consider me baited. Daevid Vincent wrote: Per Jessen wrote: Tommy Pham wrote: (I remember a list member, not mentioning his name, does optimization of PHP coding for just microseconds. Do you think how much more he'd benefit from this?) Anyone who optimizes PHP for microseconds has lost touch with reality - or at least forgotten that he or she is using an interpreted language. But sometimes it's just plain fun to do it here on the list with everyone further optimizing the last optimized snippet :) Cheers, Rob. Was that someone me? I do that. And if you don't, then you're the kind of person I would not hire (not saying that to sound mean). I use single quotes instead of double where applicable. I use -- instead of ++. I use $boolean = !$boolean to alternate (instead of mod() or other incrementing solutions). I use LIMIT 1 on select, update, delete where appropriate. I use the session to cache the user and even query results. I don't use bloated frameworks (like Symfony or Zend or Cake or whatever else tries to be one-size-fits-all). The list goes on. That's not optimization, at best it's just an awareness of PHP syntax and a vague awareness of how the syntax will ultimately be interpreted. Using LIMIT 1 is not optimizing it's just saying you only want one result returned, the SQL query could still take five hours to run if no indexes, a poorly normalised database, wrong datatypes, and joins all over the place. Using the session to cache the user is the only thing that comes anywhere near to application optimisation in all you've said; and frankly I would take to be pretty obvious and basic stuff (yet pointless in most scenario's where you have to cater for possible bans and de-authorisations) - storing query results in a session cache is only ever useful in one distinct scenario, when the results of that query are only valid for the owner of the session, and only for the duration of that session, nothing more, nothing less. This is a one in a million scenario. Bloated frameworks, most of the time they are not bloated, especially when you use them properly and only include what you need on a need to use basis; then the big framework can only be considered a class or two. Sure the codebase seems more bloated, but at runtime it's easily negated. You can use these frameworks for any size project, enterprise included, provided you appreciated the strengths and weaknesses of the full tech stack at your disposal. Further, especially on enterprise projects it makes sense to drop development time by using a common framework, and far more importantly, to have a code base developers know well and can hit the ground running with. Generally unless you have unlimited learning time and practically zero budget constraints frameworks like the ones you mentioned should always be used for large team enterprise applications, although perhaps something more modular like Zend is suited. They also cover your own back when you are the lead developer, because on the day when a more experienced developer than yourself joins the project and points out all your mistakes, you're going to feel pretty shite and odds are very high that the project will go sour, get fully re-written or you'll have to leave due to stress (of being
[PHP] SimpleXMLElement and gb2312 or big5
I use the following code to get rss and parse it, but the code occasionally have issues with gb2312 or big-5 encoded feeds, and fails to parse them. However other times may appear just okay. Any thoughts? Maybe SimpleXMLElement is simply not meant for other language encodings... $page = file_get_contents($rss); try { $feed = new SimpleXMLElement($page); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] SimpleXMLElement occasionally fails to parse gb2312 or big5 feeds
I use the following code to get rss and parse it, but the code occasionally have issues with gb2312 or big-5 encoded feeds, and fails to parse them. However other times may appear just okay. Any thoughts? Maybe SimpleXMLElement is simply not meant for other language encodings... $page = file_get_contents($rss); try { $feed = new SimpleXMLElement($page); -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetElementByClass?
On Sat, 03 Apr 2010 08:58:44 -0600, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Sat, 2010-04-03 at 10:29 -0400, tedd wrote: Hi gang: Here's the problem. I have 184 HTML pages in a directory and each page contain a question. The question is noted in the HTML DOM like so: p class=question Who is Roger Rabbit? /p My question is -- how can I extract the string Who is Roger Rabbit? from each page using php? You see, I want to store the questions in a database without having to re-type, or cut/paste, each one. Now, I can extract each question by using javascript -- document.getElementById(question).innerHTML; -- and stepping through each page, but I don't want to use javascript for this. I have not found/created a working example of this using PHP. I tried using PHP's getElementByID(), but that requires the target file to be valid xml and the string to be contained within an ID and not a class. These pages do not support either requirement. Additionally, I realize that I can load the files and parse out what is between the p tags, but I was hoping for a GetElementByClass way to do this. So, is there one? Thanks, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com I don't think there is a getElementsByClass function. HTML5 is proposing one, but that will most likely be implemented in Javascript before PHP Dom. There is a way to tidy up the HTML to make it XHTML, but I'm not sure what it is. If you know roughly where in the document the HTML snippet is you can use XPath to grab it. Failing that, what about a regex? It shouldn't be too hard to write a regex to match your example above. Thanks, Ash http://www.ashleysheridan.co.uk Somejavascript engine already support GetElementByClass, for example Opera does. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetElementByClass?
No javascript's getElementByID() won't work here. As question is a class, not an ID. But like what was mentioned here, you can use getElementByClass() with Opera, and that will work. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetElementByClass?
Yes, because Opera is pretty much leading the way with its HTML5 support. Not even Firefox supports as much as Opera does. Thanks, Ash http://www.ashleysheridan.co.uk Opera 10.10 is a very nice version, but 10.50 could be quite slow with some web pages. I still remember that once upon a time, Opera was so broken, and it also showed you that little window for ads ;-) I love to see opera get a chance, but its market share is not moving even with the release Opera 10. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetElementByClass?
Why don't you just use REGEX? I don't know any possibility to easily process contents which are not valid XML/XHTML just because there's no library to load such stuff (but put me in right there). I'm not an expert of REGEX, but I think the following would do it: /\p\s*class\=\question\\s*\(.*)\\/p\ (my first contribute here, I beg your pardon if something went wrong) Regards, Valentin Dreismann regexp is the best fit here and not much effort to do. Especially consider this is only for one time use. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetElementByClass?
Hi You could replace the class with id and then go on with JavaScript. A possible better way are regular expressions... Greetz Piero -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Yes, and jquery is hosted on Microsoft CDN, don't even need to download just plug the link in. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetElementByClass?
I think Tedds main reason not to use Javascript is that he needs it to be done on the server rather than the client machine. ps. please use bottom posting on the list. Thanks, Ash http://www.ashleysheridan.co.uk But he also mentioned that he wanted to avoid copy and paste... it does give me the feeling that this is a one time thing, and he just wanted to extract the questions. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetElementByClass?
On Sat, 03 Apr 2010 09:21:17 -0600, Ashley Sheridan a...@ashleysheridan.co.uk wrote: s, first browser to have tabs, first to have that odd homepage with thumbnails of y Talking about Opera's 'speed dial... I downloaded safari yesterday (which I didn't like last time I used it), it now has the same kind of page but with sort of 3D looking. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: array or list of objects of different types
var_dump( array( true , 12 , php already does this ) ); array(3) { [0]= bool(true) [1]= int(12) [2]= string(21) php already does this } :) Yeah. But this feature of PHP is a boon if used carefully and a curse if careless. You can get AMAZING results if you're not careful to check the data types ;) And that's why language like C# and java supports to restrict the type of data a collection can hold. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetElementByClass?
Somejavascript engine already support GetElementByClass, for example Opera does. My example shows how, namely: document.getElementById(question).innerHTML; will return the value within the class. Cheers, tedd In your original post, you said the data you had was: p class=question Who is Roger Rabbit? /p Does that still stand? or there was a typo, and class should really be ID? -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetElementByClass?
Sort of. Like I said, the folling will work: document.getElementById(question).innerHTML; While you are using a getElementById, which returns an ID, but adding .innerHTML will return the class value. Try it. Cheers, tedd No, this will not work, if it appeared working, please re-check your data, and make sure you didn't miss anything... Run the following in any browser, and see whether you get a pop up, then change class= to ID=, and run it again. body onload='alert(document.getElementById(question).innerHTML)' p class=question Who is Roger Rabbit? /p /body innerHTML works off an object, and it does nothing if youu cannot even locate the object in the first place. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetElementByClass?
It might have worked in Internet Explorer, as for a while that browser got confused over the class and id if two different elements on a page had the same class and id values. Thanks, Ash http://www.ashleysheridan.co.uk IE and Opera were the two I tested with. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] GetElementByClass?
?php // here is where you load a single file or change to iterate over a // directory of files $oDomDoc = DOMDocument::loadHTMLFile('./tedd.html'); // here is where you search for the question sections of each file $oDomXpath = new DOMXPath($oDomDoc); $oNodeList = $oDomXpath-query(//p...@class='question']); // here is where you extract the question sections of each file foreach($oNodeList as $oDomNode) var_dump($oDomNode-nodeValue); should be trivial to expand that to work w/ multiple files. Now, I can extract each question by using javascript -- document.getElementById(question).innerHTML; tedd, are you slipping? i thought you were searching by the class attribute, lol. -nathan Beautiful! -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Collections / Static typing - was array or list of objects of different types
On Sat, 03 Apr 2010 11:30:36 -0600, Nathan Rixham nrix...@gmail.com wrote: them in a google code project or suchlike. They'll obviously never be as fast as Java/C but they do allow for static typing of collections using primitive types That will be wonderful. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Constructor usage
On Sun, 04 Apr 2010 17:46:19 -0600, Nathan Rixham nrix...@gmail.com wrote: Larry Garfield wrote: Hi folks. Somewhat philosophical question here. I have heard, although not confirmed, that the trend in the Java world in the past several years has been away from constructors. That is, rather than this: class Foo { public void Foo(Object a, Object b, Object c) {} } Foo f = new Foo(a, b, c); The preference is now for this: class Foo { public void setA(Object a) {} public void setB(Object b) {} public void setC(Object c) {} } Foo f = new Foo(a, b, c); f.setA(a); f.setB(b); f.setC(c); I suppose there is some logic there when working with factories, which you should be doing in general. However, I don't know if that makes the same degree of sense in PHP, even though the OO models are quite similar. So, I'll throw the question out. Who uses example 1 above vs. example 2 when writing dependency-injection-based OOP? Why? What trade-offs have you encountered, and was it worth it? Other than theoretical reasons, one practical reason to have getters and setters is to make live easier for IDE's. I never thought the above two are in conflict. Usually parameterized constructors are provided along with getters and setters - each is used for good reasons. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Logical reason for strtotime('east') and strtotime('west') returning valid results?
On a related note: does anyone know why php -r echo date('Y-m-d H:i:s', strtotime('a')); happily outputs a valid timestamp? And why all other letters work as well (but only one character)? I'm sure there's a good reason for it, it just completely escapes me right now :) Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Little php code - error
On 8 April 2010 16:30, David Otton phpm...@jawbone.freeserve.co.uk wrote: On 8 April 2010 15:21, Juan j...@rodriguezmonti.com.ar wrote: The structure is pretty easy to understand, however I'm not able to solve this. Could you tell me why I'm not able to run this code. Your else has a condition on it } else (empty($b) and empty($c)) { Should be } else { Unless he actually wants to do something with that condition, in which case it should be an elseif. BTW, the and is fine. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] another useless message.
On 9 April 2010 12:20, Rene Veerman rene7...@gmail.com wrote: lolz :)) u try to be nice, and this is what u get?!?! :-D Rene, it's nice of you to post messages on the availability of some OS tools. However, you should also be aware that it's a minority of people on this list that use those tools - which in effect means that you're posting stuff that at best is irrelevant to a lot of people and at worst is seen as spam by those people. That said, there can be little doubt that the response you got went a tad too far - some netiquette lessons would be useful, I think. -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 404 redirects stolen by provider
On 9 April 2010 22:20, Merlin Morgenstern merli...@fastmail.fm wrote: This sounds like the best solution to me. The only problem is that my regex knowledge is pretty limited. The command: RewriteRule ^(.+) /subapp_members/search_user.php The above rule will try to redirect everything to /subapp_members/search_user.php. If you're looking to allow example.com/username, then use something like: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /subapp_members/search_user.php?member=$1 [L] This is likely to not do what you want from it, but it's the closest I can guess as to what you want. Have a read of http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 404 redirects stolen by provider
On 9 April 2010 23:08, Merlin Morgenstern merli...@fastmail.fm wrote: Am 09.04.2010 22:58, schrieb Peter Lind: On 9 April 2010 22:20, Merlin Morgensternmerli...@fastmail.fm wrote: This sounds like the best solution to me. The only problem is that my regex knowledge is pretty limited. The command: RewriteRule ^(.+) /subapp_members/search_user.php The above rule will try to redirect everything to /subapp_members/search_user.php. If you're looking to allow example.com/username, then use something like: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /subapp_members/search_user.php?member=$1 [L] This is likely to not do what you want from it, but it's the closest I can guess as to what you want. Have a read of http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html This will not work, as I do have a bunch of other redirects inside the page. What might work is a rule, that redirects urls that do not have a full stop or slash inside. Is this possible? My regex knowledge is unfortunatelly pretty limited. Try: RewriteRule ^([^./]+)$ /yourfile.php?variable=$1 [L] Apart from that, rewrite rules work in order. If a rule above this triggers and has the L flag, those below won't get processed. -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mail Function Problem
On 12 April 2010 05:22, Kevin Kinsey k...@daleco.biz wrote: Thanks to the worldwide brotherhood of crooks known as spammers, sending e-mail these days isn't nearly as easy as PHP makes it look. You might wanna look into an errors-to header to help debug any problems with sender authorization, bad ports, etc. Along these lines: there's a chance that sending a mail from yourself, to yourself, through PHP like this, will cause mail servers to think it's spam. For testing email sending, normal scenarios are better (i.e. send an email to another account). Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Solution
On 13 April 2010 00:04, Gary gwp...@ptd.net wrote: For those that were looking to see a solution, this is what I have come up with. It was pointed out on another board (MySQL) that inserting multiple in one script is probably prohibited because of security reasons. What I did was open the connection, insert into the table, close the connection, close the php script, then start over again. This is the code: $dbc=mysqli_connect('localhost','root','','test')or die('Error connecting to MySQL server'); $query=INSERT INTO name(fname, lname).VALUES('$fname','$lname'); $result=mysqli_query($dbc, $query) or die('Error querying database.'); mysqli_close($dbc); ? ?php $dbc=mysqli_connect('localhost','root','','test')or die('Error connecting to MySQL server'); $query=INSERT INTO address (street, town, state, zip).VALUES('$street','$town','$state','$zip'); $result=mysqli_query($dbc, $query) or die('Error querying database.'); mysqli_close($dbc); ? It seems a little redundant for PHP, however it seems to work. Thank you to everyone that responded. If by the way someone sees an issue with this solution, I would love to read it. Off the top of my head: just reuse the connection. There's no need to close it, then reopen it. The only security problem you're facing is that you cannot send multiple queries in *the same string*[1]. So send the queries one by one, but in the same script, using the same connection. 1. The reason this is a security concern is that otherwise, should someone manage to inject sql into your query, they could drop in a semi-colon and then start a new query. By not allowing this, a lot of bad injections are by default ruled out. -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Saving form data into session before leaving a page
On 13 April 2010 15:20, Merlin Morgenstern merli...@fastmail.fm wrote: Hello everybody, I have form where users enter data to be saved in a db. How can I make php save the form data into a session before the user leaves the page without pressing the submit button? Some members leave the page and return afterwards wondering where their already entered data is. Any ideas how to save into php session data before someone leaves the page? Use ajax: send a query to the server a couple of seconds after the user has last updated the form. Thank you for any hint, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Saving form data into session before leaving a page
On 13 April 2010 17:27, Paul M Foster pa...@quillandmouse.com wrote: On Tue, Apr 13, 2010 at 03:20:23PM +0200, Merlin Morgenstern wrote: Hello everybody, I have form where users enter data to be saved in a db. How can I make php save the form data into a session before the user leaves the page without pressing the submit button? Some members leave the page and return afterwards wondering where their already entered data is. I hate to be a contrarian (not really), but there is a paradigm for using web forms. If you want the internet to save your data, you have to press the little button. If you don't, then it won't be saved. Not hard to figure out, not hard to do. If you have to go do something else while you're in the middle of a form, open a new tab/window and do it. When you come back to your original form, the data will still be there (but again, not *saved* until you hit the little button). Sorry, I just get cranky with people who won't follow the rules. There are rules and then there's stupidity based on tradition. The fact that websites previously threw away whatever work you had done because you automatically got logged out of your session after half an hour of typing does not mean you should call this a rule that should be adhere to. Google figured it out and did so well: backup automatically and let the user discard manually - not the other way round that leads to lost work. Apart from that, I note that the OP has seemingly managed to solve the problem and all these emails are rather pointless. -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How define if javascript is on with php
Javascript is client-side - only way to detect it is to have a page send back information (post/get). What might work easiest is to have jquery look for a given cookie upon page render, and if it doesn't find it, then do an ajax call to the server. On the server side, initiate a session for the user, set using_javascript to false and update to true if you receive the ajax call. That aside, why would you need to know in the backend if a user is running javascript? On 16 April 2010 13:50, Paulo-WORK pauloworkm...@googlemail.com wrote: Hello and thanks for any replies that this message may get. I have a issue to solve regarding PHP. My website relies heavlly on jquery and does not dowgrade properly. I use codeigniter framework as this website has a backend . Is it possible to detect if js is on with php? And if so can it be set into a variable? Paulo Carvalho -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How define if javascript is on with php
On 16 April 2010 13:54, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-04-16 at 12:50 +0100, Paulo-WORK wrote: Hello and thanks for any replies that this message may get. I have a issue to solve regarding PHP. My website relies heavlly on jquery and does not dowgrade properly. I use codeigniter framework as this website has a backend . Is it possible to detect if js is on with php? And if so can it be set into a variable? Paulo Carvalho Nope, Javascript is on the client side and PHP is on the server. The server has very little knowledge of the client, and what information is sent (browser type, etc) can't be relied upon because browsers are capable of lying about what they are (in order to make themselves appear as IE for example) JQuery should allow the site to fail gracefully into a non-Javascript version, because of the way the framework is built. If this is something that you cannot easily do, why don't you just have PHP output some sort of default message that the site does not work without Javascript and use CSS to hide the rest of the site that requires script. Then, in JQuery, it's simple to hide the message and show the site with a couple of lines of code. Or use the noscript tag -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] limit to var_dump?
There's a limit to how deep var_dump goes, at least if you're using xdebug. Compare the output with that of print_r which is not limited in the same way. On 16 April 2010 16:15, Ashley Sheridan a...@ashleysheridan.co.uk wrote: I'm seeing some strange behaviour with var_dump. Is there a limit to how many levels deep that var_dump can display? Basically, my object looks like this: object(Gantt)[1] public 'tasks' = array 1 = object(Gantt_Task)[2] public 'name' = string 'task 1' (length 6) public 'predecessors' = array ... 1.1 = object(Gantt_Task)[3] public 'name' = string 'task 1.1' (length 8) public 'predecessors' = array ... 1.2 = object(Gantt_Task)[4] public 'name' = string 'task 1.2' (length 8) public 'predecessors' = array '1.1' = string 'f2s' (length 3) (full dump shortened, but it's no more than 4x the size of this output above, and the objects contain only short strings, small numbers and arrays of short strings and small numbers) However, when I var_dump the top-most object (the Gantt object) the predecessors array for Gantt_Task 1.2 just shows as '...'. If I var_dump that particular object, I can see that the correct array element does exist. Is this just a random bug I've found, or is there an intended limit to how complex and deep var_dump can go? Would it have anything to do with the fact that Gantt contains multiple instances of the Gantt_Task object? Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Replacing a special character
On 18 April 2010 16:40, Phpster phps...@gmail.com wrote: On Apr 18, 2010, at 8:59 AM, Michael Stroh st...@astroh.org wrote: I have this form that people use to add entries into a MySQL database. Recently I've had some users insert − in their entries instead of - which is causing some issues with scripts down the line. I'd like to replace the − character with -. Originally I had something like $name = mysql_escape_string($_POST[name]); which would convert the offending character to #8722; before entering it into the database. It's this encoding that is causing the problems since some scripts send out emails with this entry in their subject line which looks messy. I've tried adding the following line after the previous line to help fix this issue, however, I just got another entry with the same problem. preg_replace('/#8722;/','-',$name); Any suggestions on how others would fix this problem? I'd just like to fix it before the entry hits the database instead of creating fixes on the other end of things. Cheers, Michael -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php One option is to send an HTML email which would have the email reader interpret that code correctly Bastien Another option would be to use mysql_real_escape_string and make sure that your code and the database are using utf-8. Then when the email is sent, make sure that uses utf-8 as well. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to do i18n better?
Consider checking out http://php.net/gettext - it's the set of functions in PHP for i18n. With regards to language switching, you should consider using a url hierarchy for it, instead of just serving all pages with changing content. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mail Function Using PEAR Issues
Most, if not all, mail servers keep log files. You should look for the log files to see if the mail server has sent your mail properly or is experiencing problems (those may not feed back into PHP). Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Class constants
On 19 April 2010 10:30, Gary . php-gene...@garydjones.name wrote: Should I be able to do this: class X { const FOO = 'foo'; const FOOBAR = X::FOO . 'bar'; ... } ? Because I can't. I get syntax error, unexpected '.', expecting ',' or ';'. I assume this is because the constants are like statics which can't be initialised by functions etc. but is there really any logic behind this? It very often pays to read the PHP docs. From http://pl.php.net/manual/en/language.oop5.constants.php : The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call. So no, you shouldn't be able to do that. -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Class constants
On 19 April 2010 14:24, Gary . php-gene...@garydjones.name wrote: On Mon, Apr 19, 2010 at 10:36 AM, Peter Lind wrote: On 19 April 2010 10:30, Gary wrote: Should I be able to do this: class X { const FOO = 'foo'; const FOOBAR = X::FOO . 'bar'; ... } So no, you shouldn't be able to do that. Okay. Why not? Hate to ask, but did you at any point consider to read the PHP docs on this? The bit I sent or what you could gather from the link posted? -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to do i18n better?
On 19 April 2010 15:56, Robert Cummings rob...@interjinn.com wrote: Unless you have namespaces (and I can't remember if they completed namespaced based functions) then don't use something so commuon as a function named underscore :/ Cheers, Rob. You might want to have a look at http://pl2.php.net/_ Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP] How to do i18n better?
On 19 April 2010 12:54, Andre Polykanine an...@oire.org wrote: Hello Peter, Regarding the URL switching suggested by you and Michiel, how do I do this if I have a rather complicated .htaccess file? For instance, a blog entry URL is formed as follows: http://oire.org/menelion/entry/190/ which is phisically http://oire.org/oire.php?o=menelione=190 If I need to insert the locale somewhere inhere, sorry, I just don't know how to do that) Switch your url structure to something like /en/menelion/entry/190/ and map that to /oire.php?o=menelione=190l=en You can still default to one language and leave the language bit out of that - but when switching to a language explicitly, having that as part of the url helps. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Class constants
On 19 April 2010 16:18, Gary . php-gene...@garydjones.name wrote: On Mon, Apr 19, 2010 at 2:37 PM, Peter Lind peter.e.l...@gmail.com wrote: On 19 April 2010 14:24, Gary wrote: On Mon, Apr 19, 2010 at 10:36 AM, Peter Lind wrote: So no, you shouldn't be able to do that. Okay. Why not? Hate to ask, but did you at any point consider to read the PHP docs on this? The bit I sent or what you could gather from the link posted? Yes. The question remains. Per the PHP manual: The value must be a constant expression. Is something that depends on other classes, variables or functions constant? If you're asking why a constant should be constant, I can only point you to Ashleys answer or google. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array to csv or excel in php
On 19 April 2010 17:00, Andrew Ballard aball...@gmail.com wrote: On Mon, Apr 19, 2010 at 9:45 AM, Manolis Vlachakis vlachakis.mano...@gmail.com wrote: hallo there everyone.. i got an array from my database Help with Code Tagshttp://www.daniweb.com/forums/misc-explaincode.html?TB_iframe=trueheight=400width=680 *PHP Syntax* (Toggle Plain Texthttp://www.daniweb.com/forums/post1194347.html# ) 1. $save=split([|;],$listOfItems); and what i want i s after making some changes to the attributes on the array above to export them on an csv or excel format but directly as a message to the browser .. i dont want it to be saved on the server ... what i cant understand from the examples i found on the net .. is how to handle the files and which are created cause i just have the array in a php file nothing more... another thing i have in mind is to export from the ldap server the files directly but seems to me as the wrong way to do it thanks Often when outputting csv, I usually do something like this: ?php $fp = fopen('php://output', 'w') or die('Could not open stream'); foreach ($data as $row) { // Assumes that $row will be an array. // Manipulate the data in $row if necessary. fputcsv($fp, $row); } ? An interesting idea. I'd do: echo implode(',', $row); regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array to csv or excel in php
On 19 April 2010 17:40, Andrew Ballard aball...@gmail.com wrote: On Mon, Apr 19, 2010 at 11:14 AM, Peter Lind peter.e.l...@gmail.com wrote: On 19 April 2010 17:00, Andrew Ballard aball...@gmail.com wrote: On Mon, Apr 19, 2010 at 9:45 AM, Manolis Vlachakis 1. $save=split([|;],$listOfItems); and what i want i s after making some changes to the attributes on the array above to export them on an csv or excel format but directly as a message to the browser .. i dont want it to be saved on the server ... Often when outputting csv, I usually do something like this: ?php $fp = fopen('php://output', 'w') or die('Could not open stream'); foreach ($data as $row) { // Assumes that $row will be an array. // Manipulate the data in $row if necessary. fputcsv($fp, $row); } ? An interesting idea. I'd do: echo implode(',', $row); If it's very simple data that works, but it doesn't allow for the optional enclosure characters that fputcsv() uses in cases where a data element includes the column and/or row delimiter characters. I had originally written something using an array_map callback that did the optional enclosures as needed and then used echo implode() as you suggest, but found the solution I posted was shorter and faster. YMMV Andrew Yeah, was considering that point as well. I'd use the echo if the array values are getting modified anyway. Otherwise your solution is probably simpler. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Directory permissions question
On 19 April 2010 17:18, Al n...@ridersite.org wrote: On 4/19/2010 11:11 AM, Adam Richardson wrote: On Mon, Apr 19, 2010 at 10:59 AM, Aln...@ridersite.org wrote: I'm working on a hosted website that was hacked and found something I don't fully understand. Thought someone here may know the answer. The site has 4 php malicious files in directories owned by system [php created dirs on the site are named nobody] and permissions 755. Is there any way the files could have been written other than by ftp access or at the host root level? Clearly a php script couldn't. Thanks, Al.. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Are there any other programming options enabled on the account (Perl, JSP, Ruby, etc?) Even if the files are PHP, any of those programming options can be configured to create the files. Additionally, a vulnerability in one of the libraries leveraged to provide the hosting environment could also have provided the entry (PHP makes for a capable deliverable, but it doesn't have to provide the key for a hacking situation.) Adam Are Perl, JSP, Ruby, etc. able to ignore the dir ownership and write permissions on a Linux/Apache system? I've seen an install of Trac hacked by a file-upload - it managed to write a cron job, which then wrote to other files. It's not just a question of whether your Apache server has the correct rights/permissions, it's equally a question of: is any other part of the system getting used against me. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mail Function Using PEAR Issues
On 20 April 2010 20:17, Alice Wei aj...@alumni.iu.edu wrote: From: peter.e.l...@gmail.com Date: Mon, 19 Apr 2010 10:15:08 +0200 Subject: Re: [PHP] Mail Function Using PEAR Issues To: aj...@alumni.iu.edu CC: php-general@lists.php.net Most, if not all, mail servers keep log files. You should look for the log files to see if the mail server has sent your mail properly or is experiencing problems (those may not feed back into PHP). Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype You know where I can find that? I use Evolution Mail, a mail server? I found it through Ubuntu yesterday. Here is the link: http://projects.gnome.org/evolution/ It asks me to put in the type of mail service I used, it grabbed Google, which is smtp.google.com. I still cannot send mail. I start to wonder what is going on. Alice Evolution is a mail client, not a mail server. Apart from that, you're using the 'mail' (PHPs mail function) as the backend mailer in your PEAR script - try using smtp instead and pass the SMTP config data you normally use. Have a look at http://pear.php.net/manual/en/package.mail.mail.factory.php - the smtp part. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mail Function Using PEAR Issues
On 21 April 2010 04:25, Alice Wei aj...@alumni.iu.edu wrote: Well, from my experience with Ubuntu, looks like that it does not do that. Unless, I am doing it wrong? So did you try using the 'smtp' backend and passing all the connection details rather than 'mail'? -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] replying to list
On 21 April 2010 12:38, David McGlone da...@dmcentral.net wrote: Maybe it's not how the list is set up, but instead how people are replying to the list. One would think that in a tech world where most programmers/developers try to minimize the workload and a good programmer is lazy is seen as meaningful and/or true, more people would get annoyed with having to spend 5 seconds manually copying an email address from one field to another when there is in fact a solution to this problem (and has been for a very long time): proper setup of the mailing list with a 'reply-to' field. (and no, I don't think the possibilities of a misconfigured OoO/autoreply is worth the hassle to the amount of people using this mailing list - there are mail filters for things like that). -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] replying to list (I give up)
On 21 April 2010 14:38, Hans Åhlin ahlin.h...@kronan-net.com wrote: Why change the way that has been around for years and adopted by multiple e-mail lists? It feels like it's more problem to change the way for thousands of users just to satisfy a couple of few. David was venting based on a discussion in another thread. I'm pretty sure he knows about the option to reply-all - that's part of the reason for venting (it sends multiple emails instead of just the one needed). The optimal scenario is to: 1) be able to quickly respond to the list, as that's the normal action you want to do and 2) not spam people with several emails for no reason (i.e. avoid replying to the OP AND the list). -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] replying to list (I give up)
On 21 April 2010 15:41, Dan Joseph dmjos...@gmail.com wrote: When you hit reply all, just take out all the other addresses and leave the list one in there. The list was setup like this years ago on purpose, and they've stated in the past they don't want to change it.. And waste time every single time you post to the list ... why do people become programmers/developers again? To end creating technical solutions they can then avoid using by doing extra, pointless manual work? Anyway, if there's no chance of changing the minds of the people administering the list, the discussion might as well end now. -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] replying to list (I give up)
On 21 April 2010 14:56, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Wed, 2010-04-21 at 08:56 -0400, David McGlone wrote: On Wed, 2010-04-21 at 14:42 +0200, Daniel Egeberg wrote: On Wed, Apr 21, 2010 at 14:27, David McGlone da...@dmcentral.net wrote: I give up. trying to reply to messages on this list is tedious. I can't pinpoint whether it's because the list is set up to make replies go to the OP or the OP has his reply-to in his mail client set, or most people are hitting the reply-to button instead of simply reply. Then get a better email client if yours doesn't support reply to all or reply to group. It's hardly the mailing list's fault that your client doesn't support that. My email client does support reply to all, but it's IMHO inconsiderate. Think about people that have to pay for every Mb they download. reply to all causes these people to have to pay for duplicates. Now if somebody on this list was paying for their downloads, then you and I am costing them money by using reply to all and now there are 2 duplicate messages for them the download. How would you feel if this was you? -- Blessings, David M. Did you read the link that David Robley sent on the original thread you made? http://www.unicom.com/pw/reply-to-harmful.html What you're proposing would cause a lot of problems for the sake of a few people. And I hardly think that a few emails are going to cause a bandwidth issue for anybody. If bandwidth was such an issue, they'd be using an email client that only downloaded the email headers first, and from there you could easily discern the duplicate messages. Except it wouldn't cause a lot of problems, now would it? As you've heard from quite a few others, many mailing lists work using the 'reply-to' ... and have happy users. Most of the points in the doc you posted a link to are viewpoints from someone that's used to one thing and hates the idea of things changing - whether or not it makes life easier (the It makes things break for instance ... calling replying to the list instead of the OP a break is rather farfetched unless you've stared at something you hate for so long you've become blinded byt it. Then there's the Freedom of choice: well, where's my freedom of choice? I can't use 'reply' as I want to, so it's effectively reduced *my* freedom). Quick guess is by now, the majority of people clicking reply *mean* to reply to the list but in effect reply to the OP. Using reply-to would help these people. Anyone using reply-all would see no difference. So when you're advocating that many subscribers should ditch their email client and install Evolution instead of having *one* email list have it's settings changed a bit ... I start to wonder if you've considered things from both sides. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: replying to list (I give up)
On 21 April 2010 20:09, Michelle Konzack linux4miche...@tamay-dogan.net wrote: Hello Peter Lind, Hi Michelle Am 2010-04-21 15:47:54, hacktest Du folgendes herunter: And waste time every single time you post to the list ... why do people become programmers/developers again? To end creating technical solutions they can then avoid using by doing extra, pointless manual work? Hmmm, being a Programmer/Developer since 1982 and have ever used decent tools to accomplish a task... including the right MUA which simplify the Programmers/Developers daily mailing tasks. Making it the problem of the MUA is a hack, not a solution. If you really want to go down the I have experience route I'd expect you to choose the fix the problem at the root-solution not the lets hack it by leaving the problem as is and requiring everyone to choose a proper tool-hack. Anyway, if there's no chance of changing the minds of the people administering the list, the discussion might as well end now. Why should Programmers/Developers bother with non-reliable MUAs which do not support Programmers/Developers daily mailing tasks? If YOU are a Programmer/Developer why do you bother with a non-suitable MUA? Please don't make assumptions about me and my tools - you have no basis for them. Apart from that, I see no reason to call MUAs 'suitable' based on whether or not they fix a problem that should be fixed elsewhere. If I'm not mistaken, we're faced with a quite simple cost/benefit scenario: how many people want to reply just to the list when responding and how many people want to reply just to the OP when responding. If the first number is higher than the second, then we're imposing extra work on people (either by asking them to manually fix email addresses or by bullying them into changing email clients) if we stick to the solution that fit the second group. But it's still a moot point, as the admins of the list won't be changing settings. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: replying to list (I give up)[SOLVED TO A DEGREE]
On 22 April 2010 12:14, Ashley Sheridan a...@ashleysheridan.co.uk wrote: I believe Dan Brown mentioned a very good reason why this is not as simple an issue as just changing the reply-to. Not everyone who posts to the list subscribes to the list, so being copied into the emails is good for them. Suddenly changing the way things work could actually be detrimental to the list. Imagine how many people joined up *after* posting a question and receiving a good answer. That wouldn't change - they only get copied in when you choose 'reply-all' and that would work the same whether or not a 'reply-to' is used. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: replying to list (I give up)[SOLVED TO A DEGREE]
On 22 April 2010 17:05, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Thu, 2010-04-22 at 17:06 +0200, Peter Lind wrote: On 22 April 2010 12:14, Ashley Sheridan a...@ashleysheridan.co.uk wrote: I believe Dan Brown mentioned a very good reason why this is not as simple an issue as just changing the reply-to. Not everyone who posts to the list subscribes to the list, so being copied into the emails is good for them. Suddenly changing the way things work could actually be detrimental to the list. Imagine how many people joined up *after* posting a question and receiving a good answer. That wouldn't change - they only get copied in when you choose 'reply-all' and that would work the same whether or not a 'reply-to' is used. Regards Peter It would change for the first reply. You say you just want to hit reply to reply to the list. Now if anyone hits reply, because the reply-to' header has been changed, the reply goes to the list and not the op. They're not subscribed and so they miss out. You seem to forget the amount of people stating remove the other addresses from the reply-all response. Also, if you don't want to subscribe to a mailing list, the onus is really on you to make sure you get the response if any comes. The way things stand, hitting reply instead of reply to all sends the reply back to the op only. It happens on this list often and doesn't cause many issues as the op or replyer notices and sends/copies the list back in again. It's rather annoying and easily avoided. The question is whether this problem is bigger than people not subscribed to the list not getting a response, because people use reply instead of reply all. Changing the reply-to header would mean that if someone just hit reply, the unsubscribed op wouldn't get the reply at all, and any further replies to that thread would all be to the list only and the unsubscribed op would never know. Emailing a mailing list and expecting an automated response is ... I don't want to be negative or arrogant, but I think there's a general and rather problematic lack of experience there. It's a bit like walking past a group of people, yelling a question at them, then expecting one of them to run back to you with the answer after you've passed. Would you normally expect that kind of behaviour? Apart from that, if in the current scenario you just hit 'reply' and send the email off to the OP, the list doesn't get the benefit - and the OP is not going to change that fact, as they're not subscribed to the list and won't notice anyway. Which is worse, one person having to check the answer by looking at the mailing list archive or the rest of the list not benefiting at all from the answer? Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Structured PHP studying
On 23 April 2010 13:15, David McGlone da...@dmcentral.net wrote: Is there a good strategy to studying PHP? For instance, is there a way to break everything down into small managable topics? The Zend study guide might be a place to start - not for free thought, so there may be better options (it's also directed at getting Zend certified, so it's covering the stuff you need to know for that, not connected things). Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] creating a PHP wrapper script?
php.net/curl should be able to do what you want. file_get_contents with a proper stream context should also work (have a look at functions like http://dk.php.net/manual/en/context.http.php ) Regards Peter On 23 April 2010 17:18, Robert P. J. Day rpj...@crashcourse.ca wrote: i'm sure this isn't hard to do, but i'm having end-of-week brain cramps. just now, i installed a PHP package that lets me download thumbnails of image files stored on a server -- the URL to generate and download a thumbnail is, say: http://server/d1/d2/thumbnail.php?fileID=whateverarg1=val1arg2=val2 and so on. unsurprisingly, the thumbnail generation program accepts numerous arguments and is incredibly sophisticated, and is stored in a subdirectory under /var/www/html and ... well, you get the idea, calling it directly involves creating quite the URL. instead, i'd like to stuff a wrapper script at the top of the document root which hides all that complexity, so i can just browse to: http://server/thumb.php?fileID=whatever and have that top-level thumb.php script make the appropriate invocation to the real thumbnail.php script with all of those (default) arguments and values. so, what would thumb.php look like? i obviously need to simulate a POST call, retrieve the output and pass it back unchanged. thoughts? surely this is something that people want to do on a regular basis, no? rday -- Robert P. J. Day Waterloo, Ontario, CANADA Linux Consulting, Training and Kernel Pedantry. Web page: http://crashcourse.ca Twitter: http://twitter.com/rpjday -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] public readonly variables
On 23 April 2010 18:10, Ashley Sheridan a...@ashleysheridan.co.uk wrote: I think for now I'll just resort to leaving it as a public variable. I'll leave the specific set function for it in and just hope that is used instead! As it's only me who'll be using it for the time being, I can always yell at myself later if I forget! You're using a setter but a public variable? That's about the worst compromise, isn't it? Either go down the road of the public variable or the setter/getter (and in your case I would definitely recommend the latter). Also, __get/__set are fine, as long as you don't use them for everything (i.e. 5 magic calls per request will do very, very little to your app, whereas 1000 per request will have some significance on a site with lots of users). Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] public readonly variables
On 23 April 2010 18:26, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2010-04-23 at 12:25 -0400, Adam Richardson wrote: On Fri, Apr 23, 2010 at 12:21 PM, Peter Lind peter.e.l...@gmail.com wrote: On 23 April 2010 18:10, Ashley Sheridan a...@ashleysheridan.co.uk wrote: I think for now I'll just resort to leaving it as a public variable. I'll leave the specific set function for it in and just hope that is used instead! As it's only me who'll be using it for the time being, I can always yell at myself later if I forget! You're using a setter but a public variable? That's about the worst compromise, isn't it? Either go down the road of the public variable or the setter/getter (and in your case I would definitely recommend the latter). Also, __get/__set are fine, as long as you don't use them for everything (i.e. 5 magic calls per request will do very, very little to your app, whereas 1000 per request will have some significance on a site with lots of users). Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype I agree with Peter, that solutions asks for trouble (something I often do, but avoid publicly advocating ;) The solution I suggested still maintains all of the documentation capabilities (at least in my NetBeans), but enforces protection. It's not perfect, but it does work relatively well. Adam I am probably looking at a lot of getters in the code though, so the overhead I'd rather avoid. The setter is to go some way towards keeping the values sane, which I realise goes against the whole public variable thing, which is the reason for my original question. Another reason for the setter is that it actually modifies a couple of variables, so there's no good way of getting rid of that, as it would then mean setting two properties of the object manually, which would actually lead to more issues down the line if not set correctly. If you're just creating the project now, I'd autogenerate the classes, to avoid the manual work. Otherwise, I'd give it some long thought then grit my teeth and dig in. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP not being read?
On 25 April 2010 05:00, Gary g...@paulgdesigns.com wrote: Karl On the laptop, the original machine, it has Vista, Firefox 3.6.3. Previewing on testing server Apache (XAMPP )on the computer, not network On the tower, it is running XP Pro, Firefox 3.6.3. Previewing on local testing server. Check that the php module is loaded by Apache on the 'bad' machine and that the proper handler is set. Should be a line like: AddHandler application/x-httpd-php .php .phtml .php3 in the php5.conf file (look in mods-enabled, if you're running Apache2 - I'm hoping the setup is the same under Vista as *nix) Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Weird problem with is_file()
On 25 April 2010 22:14, Michelle Konzack linux4miche...@tamay-dogan.net wrote: Hi, I have a code sniplet which does not work and I do not know why: 8-- $isfile=shell_exec(ls /tmp/tdphp-vserver/SESSION_ . $_SERVER['REMOTE_ADDR'] . _ . $_COOKIE['VSERVER_AUTHUSER'] . _* |head -n1); if (is_file($isfile)) { snip 8-- nothing special, and the file is there, but the stuff with is_file($isfile) is not working... If I enter the file in place of $isfile, then it is working. Quoting of $isfile does not work too. What have a overseen? var_dump($isfile); Don't make assumptions of what the value is, just check it. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting content exceprts from the database
On 26 April 2010 12:52, Ashley Sheridan a...@ashleysheridan.co.uk wrote: I've been thinking about this problem for a little while, and the thing is, I can think of ways of doing it, but they're not very nice, and I don't think they're going to be fast. Basically, I have a load of HTML formatted content in a database that get displayed onto the site. It's part of a rudimentary CMS. Currently, the titles for each article are displayed on a page, and each title links to the full article. However, that leaves me with a page which is essentially a list of links, and that's not ideal for SEO. What I wanted to do to enhance the page is to have a short excerpt of x number of words/characters beneath each article title. The idea being that search engines will find the page as more than a link farm, and visitors won't have to just rely on the title alone for the content. Here's the rub though. As the content is in HTML form, I can't just grab the first 100 characters and display them as that could leave an open tag without a closing one, potentially breaking the page. I could use strip_tags on the 100-character excerpt, but what if the excerpt itself broke a tag in half (i.e. acronym title=something could become acron ) The only solutions I can see are: * retrieve the entire article, perform a strip_tags and then take the excerpt * use a regex inside of mysql to pull out only the text The thing is, neither of these seems particularly pretty, and I am sure there's a better way, but it's too early in the week for my brain to be fully functional I think! Does anyone have any ideas about what I could do, or do you think I'm seeing problems where there are none? Use htmltidy or htmlpurifier to clean up things. I.e. grab the amount of content you want, then use one of the tools to repair and clean the html. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] getting content exceprts from the database
On 26 April 2010 13:23, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Mon, 2010-04-26 at 13:20 +0200, Peter Lind wrote: On 26 April 2010 12:52, Ashley Sheridan a...@ashleysheridan.co.uk wrote: I've been thinking about this problem for a little while, and the thing is, I can think of ways of doing it, but they're not very nice, and I don't think they're going to be fast. Basically, I have a load of HTML formatted content in a database that get displayed onto the site. It's part of a rudimentary CMS. Currently, the titles for each article are displayed on a page, and each title links to the full article. However, that leaves me with a page which is essentially a list of links, and that's not ideal for SEO. What I wanted to do to enhance the page is to have a short excerpt of x number of words/characters beneath each article title. The idea being that search engines will find the page as more than a link farm, and visitors won't have to just rely on the title alone for the content. Here's the rub though. As the content is in HTML form, I can't just grab the first 100 characters and display them as that could leave an open tag without a closing one, potentially breaking the page. I could use strip_tags on the 100-character excerpt, but what if the excerpt itself broke a tag in half (i.e. acronym title=something could become acron ) The only solutions I can see are: * retrieve the entire article, perform a strip_tags and then take the excerpt * use a regex inside of mysql to pull out only the text The thing is, neither of these seems particularly pretty, and I am sure there's a better way, but it's too early in the week for my brain to be fully functional I think! Does anyone have any ideas about what I could do, or do you think I'm seeing problems where there are none? Use htmltidy or htmlpurifier to clean up things. I.e. grab the amount of content you want, then use one of the tools to repair and clean the html. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype Would that work on content that stopped mid-tag? Assuming the original copy is: pThis is some sentence, with an abbr title=Abbreviationabbr/abbr in the middle of it./p If I was asking for only the first 50 characters, I'd get this: pThis is some sentence, with an abbr title=Abb Would either htmltidy or htmlpurifier be able to handle that? I don't mind whether it tries to repair the tag or remove it completely, as long as it does something to it. Thanks, Ash http://www.ashleysheridan.co.uk HTMLTidy should definitely do something to it, pretty sure it's able to clean that up so you get working html. Same for HTMLPurifier (the latter is not as much what you're looking for, it protects against injections more than validating html - so disregard that I mentioned that one for now :) ). Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Error handling strategies (db related)
On 27 April 2010 10:42, Gary . php-gene...@garydjones.name wrote: How do you guys handle errors during, say, db insertions. Let's say you have an ongoing transaction which fails on the n-th insert. Ok, you roll back the transaction, no problem. How do you then inform the user? Just using the text from pg_result_error or something? If it's a normal user, give them some info about what went wrong but not the specific error returned. If it's an admin with dev knowledge (i.e. you) then consider handing out the returned error as well. Rule of thumb: aim to inform the user without confusing. There's nothing worse than This didn't work, sorry - why didn't it work?? Was it my fault? Can I get it to work somehow? Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Weird while issue
On 27 April 2010 14:36, Juan Rodriguez Monti j...@rodriguezmonti.com.ar wrote: Hi guys, I have some issues with while. I have an HTML Form, that uses GET to process its contents. Then there's a PHP Script that receives the data, and evaluates the fields. So, in some instance of the code, I do something like : if (empty($a) AND empty($b)) { echo something; echo something; echo something; while ($row = sqlite_fetch_array($results,SQLITE_BOTH)) { And here I print some echo's to print an HTML's Table with the results of the while. echo Something more; echo etc; } } elseif (empty($c) AND empty($d)) { Here there is another elseif similar to the first one explained above. } I have four or five elseif's that analizes the fields of the HTML's Form and then the PHP's Code do things depending of the combinations of fields submited and so on. The problem is that if I want to add an echo saying Come Back to Index to index.html, I'm not able to show it after the while's iteration. The PHP code prints the table with its results taken from SQlite perfectly. Also it evaluates all the conditions flawessly. However, If I add a link to come back with the text Go to Index after the while and before the } close to the next elseif, PHP prints it in the wrong ubication. I got something like: TITLE *** Go to Index *** While results. This is the table containing all the results of the SQlite's Query. If I move the echo to other part of the block, I receive so many echo's as iterations the while do ( this is logical ). However I don't understand why the echo is printed above the while even when I put it after the while and out of the while's block. Check your html for broken html table code. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Error handling strategies (db related)
On 27 April 2010 15:36, Paul M Foster pa...@quillandmouse.com wrote: On Tue, Apr 27, 2010 at 10:42:03AM +0200, Gary . wrote: How do you guys handle errors during, say, db insertions. Let's say you have an ongoing transaction which fails on the n-th insert. Ok, you roll back the transaction, no problem. How do you then inform the user? Just using the text from pg_result_error or something? I use trigger_error() and stop execution at that point. I give the user an error that basically says, Talk to the admin/programmer. And I send the programmer a message containing a trace of what occurred. The theory is that, all things being equal, such an error should never occur and there is no user recovery. If the user properly entered the data they were asked for, then the transaction should go through without incident. If something prevents the transaction from going through, it's likely a coding problem and up to the programmer or admin to repair. Fair reasoning, but it amounts to throwing a bucket of cold water in the face of your user. If I was looking at an error like that, I'd get mighty annoyed with the software, and after a while would definitely look for alternatives. Whether or not there's a coding problem, you have to look at the situation from the point of the user: a complete failure with no information is like a BSOD/TSOD ... and we all know the effect they have on a user. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Error handling strategies (db related)
On 27 April 2010 16:07, Paul M Foster pa...@quillandmouse.com wrote: On Tue, Apr 27, 2010 at 03:41:04PM +0200, Peter Lind wrote: On 27 April 2010 15:36, Paul M Foster pa...@quillandmouse.com wrote: On Tue, Apr 27, 2010 at 10:42:03AM +0200, Gary . wrote: How do you guys handle errors during, say, db insertions. Let's say you have an ongoing transaction which fails on the n-th insert. Ok, you roll back the transaction, no problem. How do you then inform the user? Just using the text from pg_result_error or something? I use trigger_error() and stop execution at that point. I give the user an error that basically says, Talk to the admin/programmer. And I send the programmer a message containing a trace of what occurred. The theory is that, all things being equal, such an error should never occur and there is no user recovery. If the user properly entered the data they were asked for, then the transaction should go through without incident. If something prevents the transaction from going through, it's likely a coding problem and up to the programmer or admin to repair. Fair reasoning, but it amounts to throwing a bucket of cold water in the face of your user. If I was looking at an error like that, I'd get mighty annoyed with the software, and after a while would definitely look for alternatives. Whether or not there's a coding problem, you have to look at the situation from the point of the user: a complete failure with no information is like a BSOD/TSOD ... and we all know the effect they have on a user. I assume (1) that I've vetted the user data and given them the option to repair it if it's faulty; (2) beyond the beta phase, this type of error should not happen. If it does, it's a coding problem. Given that the user can do *nothing* about this and it *is* a coding problem, what would you tell the user? Sorry, but there was a problem inserting the data into the database. The developers have been notified about this error and will hopefully have it fixed very soon. We apologize for the inconvenience. At the very least, something along those lines. If I was the user, I'd be cranky as well. But if I were a smart user, I'd realize that the programmer made a mistake and put the responsibility firmly on him. And expect him to fix it pronto. If only the world consisted of smart users ... I think, however, that we're generally closer to the opposite. And no, I don't hate users - I've just seen too many people do things that were very far removed from smart. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Error handling strategies (db related)
On 27 April 2010 16:24, Paul M Foster pa...@quillandmouse.com wrote: On Tue, Apr 27, 2010 at 04:13:20PM +0200, Peter Lind wrote: On 27 April 2010 16:07, Paul M Foster pa...@quillandmouse.com wrote: On Tue, Apr 27, 2010 at 03:41:04PM +0200, Peter Lind wrote: On 27 April 2010 15:36, Paul M Foster pa...@quillandmouse.com wrote: On Tue, Apr 27, 2010 at 10:42:03AM +0200, Gary . wrote: How do you guys handle errors during, say, db insertions. Let's say you have an ongoing transaction which fails on the n-th insert. Ok, you roll back the transaction, no problem. How do you then inform the user? Just using the text from pg_result_error or something? I use trigger_error() and stop execution at that point. I give the user an error that basically says, Talk to the admin/programmer. And I send the programmer a message containing a trace of what occurred. The theory is that, all things being equal, such an error should never occur and there is no user recovery. If the user properly entered the data they were asked for, then the transaction should go through without incident. If something prevents the transaction from going through, it's likely a coding problem and up to the programmer or admin to repair. Fair reasoning, but it amounts to throwing a bucket of cold water in the face of your user. If I was looking at an error like that, I'd get mighty annoyed with the software, and after a while would definitely look for alternatives. Whether or not there's a coding problem, you have to look at the situation from the point of the user: a complete failure with no information is like a BSOD/TSOD ... and we all know the effect they have on a user. I assume (1) that I've vetted the user data and given them the option to repair it if it's faulty; (2) beyond the beta phase, this type of error should not happen. If it does, it's a coding problem. Given that the user can do *nothing* about this and it *is* a coding problem, what would you tell the user? Sorry, but there was a problem inserting the data into the database. The developers have been notified about this error and will hopefully have it fixed very soon. We apologize for the inconvenience. At the very least, something along those lines. Well of course. No reason to slap the user in the face. I agree. But in the end, this is about the same as saying, Talk to the programmer, just a nicer way of saying it. Of course, it's just a question of degree. If the user can't correct the error, there's only one person that can: the programmer. Question is what you tell the user in that situation. If I was the user, I'd be cranky as well. But if I were a smart user, I'd realize that the programmer made a mistake and put the responsibility firmly on him. And expect him to fix it pronto. If only the world consisted of smart users ... I think, however, that we're generally closer to the opposite. And no, I don't hate users - I've just seen too many people do things that were very far removed from smart. Unfortunately, true. Sometimes I think computer users should be required to take a course in using a computer before being allowed behind the keyboard. While I love to rant at stupid users, the truth is probably that programmers are the ones who should take courses in how users think. In the end, if I fail to understand my users, it doesn't matter how great my program is: they'll still fail to use it. Anyway, those are just truisms :) Nothing new under the sun. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Error handling strategies (db related)
On 27 April 2010 18:21, tedd tedd.sperl...@gmail.com wrote: At 4:31 PM +0200 4/27/10, Peter Lind wrote: While I love to rant at stupid users, the truth is probably that programmers are the ones who should take courses in how users think. In the end, if I fail to understand my users, it doesn't matter how great my program is: they'll still fail to use it. Anyway, those are just truisms :) Nothing new under the sun. Regards Peter Peter: You're right on. I just read three books on the subject: 1. Don't Make Me Think by Steve Krug. This is a somewhat dated book, but his perspective is right-on and is the basis for understanding usability. +1. Great book that is. 2. Neuro Web Design bu Susan M. Weinschenk. The theory behind why people do what they do is explained in great detail in this book. It makes a great book to read regardless of if you're trying to sell something on the net or elsewhere. However, this book is focused on selling things to people via the net. Will have to look at that, sounds interesting. 3. Rocket Surgery Made Easy by Steve Krug. This is the second book in Steve's How to do it yourself in usability studies. It will give you exactly what you need to do to set up inexpensive usability studies. Usability studies are important in software and web design. If developers (and clients) read those books, we would have less problems dealing with users. Haven't read his second, guess I should :) Thanks for the recommendations. Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What is wrong with this code?
On 28 April 2010 08:39, Gary . php-gene...@garydjones.name wrote: class Pg_Error { private static $errors = array(INTEGRITY_CONST_UNIQUE = 'uniqueness constraint violated'); ... public static function getMessage($ec) { $text = ''; if (array_key_exists($ec, Pg_Error::$errors)) { $text = Pg_Error::$errors[$ec]; } return $text; } ... } ? Calling it, the array_key_exists call always returns false: $this-assertEquals('uniqueness constraint violated', Pg_Error::getMessage(Pg_Error::INTEGRITY_CONST_UNIQUE)); and I can't see what I've done wrong :( In your code snippet, you do not declare Pg_Error::INTEGRITY_CONST_UNIQUE - and equally to the point, in the class you only use INTEGRITY_CONST_UNIQUE in the array, not Pg_Error::INTEGRITY_CONST_UNIQUE Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] What is wrong with this code?
On 28 April 2010 10:57, Gary . php-gene...@garydjones.name wrote: On 4/28/10, Jochem Maas wrote: class Pg_Error { const INTEGRITY_CONST_UNIQUE = '23505'; this is a class constant private static $errors = array(INTEGRITY_CONST_UNIQUE = 'uniqueness constraint violated'); [...] unfortunately you cannot use a classes own constants in the definition of the $errors var Huh? IWFM. Is it defined in the language that it does not work, or might not work depending on the runtime environment? IMO it should work (given the declaration order) but I know statics do have a tendency (certainly in other laguages) to be somewhat special. Shouldn't be any problems using a classes constants in the definition of an array in the same class. However, to avoid possible extra work down the line, I wouldn't use Pg_Error::YOUR_CONSTANT inside the class, I'd use self::YOUR_CONSTANT Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Project TIME calculated, in PHP
On 1 May 2010 22:02, Richard Quadling rquadl...@googlemail.com wrote: On 1 May 2010 18:48, justino garcia jgarciaitl...@gmail.com wrote: tImeArrived = CDate(InputBox(Enter START time:, Start time, 9:00 AM)) TimeLeft = CDate(InputBox(Enter END time:, End time, 1:24 PM)) Minutes = DateDiff(n, TimeArrived, TimeLeft) Hours = Int(Minutes / 60) Minutes = Minutes - (Hours * 60) TotalTime = Format(Hours, 0) : Format(Minutes, 00) I did something like this in VBA, but I want to create something for PHP. How can extract an am or pm from the input string, convert to 24 hours for calculations, then convert back to 12 hour am/pm format in PHP? Consider the DateTime class, might suit your needs. http://dk2.php.net/manual/en/class.datetime.php Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php