[PHP] Re: PHP images server
'Twas brillig, and Jean-Michel Philippon-Nadeau at 04/08/10 16:48 did gyre and gimble: Hi List, My website uses a lot of external images coming from many different websites. Those images are sometimes small, sometimes big, and to reduce the loading time of my pages and for better uniformity, I've built a small PHP images server that resizes to a predefined set of dimensions the images if necessary. To save on CPU usage, the resized version is stored on Amazon AWS. When requesting an image of a specific size, if the resized image exists on AWS, that image is used. The images server then redirects the browser to the AWS URL. I don't believe having 80 redirections is a very clean solution so, my question is: How can I optimize my process while keeping the load on Amazon's servers? Presumably you generate the links to the files to put into HTML or CSS at some point? Rather than check if an appropriate sized image is available then the image is requested, why not check when you generate the link to the the image? If when you generate the link it is NOT available, do the necessary stuff to generate it and upload to AWS, then carry on. Col -- Colin Guthrie gmane(at)colin.guthr.ie http://colin.guthr.ie/ Day Job: Tribalogic Limited [http://www.tribalogic.net/] Open Source: Mandriva Linux Contributor [http://www.mandriva.com/] PulseAudio Hacker [http://www.pulseaudio.org/] Trac Hacker [http://trac.edgewall.org/] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Converting HTML to PDF via PHP
I am trying to export generated HTML (an invoice for a customer) to a saveable PDF that is downloaded. Any ideas? I've found a very easy unix command for generating PDF's: code.google.com/p/wkhtmltopdf [The PHP list wouldn't let me send this with http://; in front of the URL.] It will turn any web page into a PDF and was easy to install and use and has documentation. (I call it from a PHP script.) It renders the web page using a WebKit library that's included in the source, and there are lots of options for how to tweak the rendering engine. Scott -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP The Anthem
http://www.youtube.com/watch?v=S8zhmiS-1kw http://shiflett.org/blog/2010/aug/php-anthem ...some people have way too much time. ;-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP The Anthem
That. That is awesome. I will be forwarding this to some perl people now. Regards, -Josh On Aug 5, 2010, at 7:57 PM, Daevid Vincent wrote: http://www.youtube.com/watch?v=S8zhmiS-1kw http://shiflett.org/blog/2010/aug/php-anthem ...some people have way too much time. ;-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quotes vs. Single Quote
On Aug 5, 2010, at 10:10 PM, Rick Dwyer wrote: Hi List. I've mentioned before that I am both just beginning to learn PHP AND I have inherited a number of pages that I'm trying to clean up the w3c validation on. Something that confuses me is how the code on the page is written where in one instance, it follows this: echo table border='1'tr And elsewhere on the page it follows: echo 'table border=1tr In what I've read and from many of the suggestions from this board, the latter seems to be the better way to code, generally speaking. So given that the page has javascript in it, perhaps the reason for the previous developer switching between the two was for ease of incorporating JS? Don't really know... but what I would like to know is it considered poor coding switch between the two on a single page or is it perfectly acceptable? 2nd question, in the 3 lines below: $_SESSION['newpage'] = $newpage; $checkstat = select field from table where fieldid = $field_id; $result1 = @mysql_query($checkstat,$connection) or die(Couldn't execute query); If I were to recode in the latter style, should they not look like this: $_SESSION['newpage'] = $newpage; $checkstat = 'select field from table where fieldid = '.$field_id.''; $result1 = @mysql_query($checkstat,$connection) or die('Couldn\'t execute query'); The focus being here: '.$field_id.''; ('Couldn\'t execute query') Is this correct? Thanks for the help. --Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Rick- It is generally accepted that you should use single quotes whenever possible. I only use double quotes when writing SQL queries (so I don't have to continually escape them for the single quotes) and when I need to output control characters like \r or \n. It would be considered best practice to make consistent use of them, but it wouldn't be something I would loose sleep over. Regards, -Josh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quotes vs. Single Quote
On Aug 5, 2010, at 10:43 PM, Michael Shadle wrote: On Thu, Aug 5, 2010 at 7:10 PM, Rick Dwyer rpdw...@earthlink.net wrote: Hi List. I've mentioned before that I am both just beginning to learn PHP AND I have inherited a number of pages that I'm trying to clean up the w3c validation on. Something that confuses me is how the code on the page is written where in one instance, it follows this: echo table border='1'tr And elsewhere on the page it follows: echo 'table border=1tr In what I've read and from many of the suggestions from this board, the latter seems to be the better way to code, generally speaking. So given that the page has javascript in it, perhaps the reason for the previous developer switching between the two was for ease of incorporating JS? Don't really know... but what I would like to know is it considered poor coding switch between the two on a single page or is it perfectly acceptable? 2nd question, in the 3 lines below: $_SESSION['newpage'] = $newpage; $checkstat = select field from table where fieldid = $field_id; $result1 = @mysql_query($checkstat,$connection) or die(Couldn't execute query); You could always do: $result1 = mysql_query(SELECT field FROM table WHERE fieldid = $field_id, $connection) or die(Couldn't execute query); a) I capped SQL verbs. Make it more readable :) b) why make a variable just to throw it in the next line? c) Make sure $field_id is truly an integer. If not, intval, mysql_escape_string, something along those lines. Also put it in single quotes if not an integer. d) I left double quotes in the error, because it has a single quote inside of it. The small micro-optimization performance you might get is probably not worth the readability factor. My general rules of thumb: I use double quotes if: a) I have single quotes inside the string b) I need variables to be parsed c) I need control characters like \n parsed I use single quotes always: a) For array indexes $foo['bar'] b) If I don't need variable parsing, control characters, etc. why not? You'll get a minimal performance gain by using single quotes everywhere in PHP where you don't -need- double quotes, but that's a micro-optimization and there's probably more important things for you to be doing. For HTML, -always- use double quotes. tag attribute=bar / is the right way. tag attribute='bar' / is the wrong way. I'd go into more explanation but there simply doesn't need to be one. Michael: Well put.. exactly the type of instruction I was looking for. Thanks, --Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quotes vs. Single Quote
On Thu, Aug 5, 2010 at 10:53 PM, Rick Dwyer rpdw...@earthlink.net wrote: On Aug 5, 2010, at 10:43 PM, Michael Shadle wrote: For HTML, -always- use double quotes. tag attribute=bar / is the right way. tag attribute='bar' / is the wrong way. I'd go into more explanation but there simply doesn't need to be one. I would suggest that saying tag attribute='bar' / is the wrong way is a rather strong assessment. Whether you're talking about SGML (the grandparent), XML (the parent), or XHTML, the use of a single quote is perfectly valid, and has served a purpose since inception. If I'm crafting markup and embedding something that has a double quote within an attribute (often times an alt attribute on an image), I don't hesitate to use the single quote as the attribute delimiter. That said, it's often easier if you standardize on one, and most choose to use double quotes the default delimiter. Tim Bray, who knows a little bit about XML dialects (tongue in cheek), appears to default to the single quote as his delimiter of choice: http://www.tbray.org/ongoing/ Now, speaking to questions/concerns about javascript events frequent use of single quotes beg the question: Why are you embedding javascript events into the markup of the page? I'm aware of many sources that advocate against mixing javascript and html in this way (see the books PPK on Javascript, DOM Scripting, etc.) That said, if there are some sources to point to that make a case for the deprecation of single quotes in (X)HTML attributes, please let me know. Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com
Re: [PHP] Quotes vs. Single Quote
On Thu, Aug 5, 2010 at 8:51 PM, Adam Richardson simples...@gmail.com wrote: I would suggest that saying tag attribute='bar' / is the wrong way is a rather strong assessment. Whether you're talking about SGML (the grandparent), XML (the parent), or XHTML, the use of a single quote is perfectly valid, and has served a purpose since inception. If I'm crafting markup and embedding something that has a double quote within an attribute (often times an alt attribute on an image), I don't hesitate to use the single quote as the attribute delimiter. That said, it's often easier if you standardize on one, and most choose to use double quotes the default delimiter. That said, if there are some sources to point to that make a case for the deprecation of single quotes in (X)HTML attributes, please let me know. Well, most people use htmlspecialchars() to encode text for safe display to a browser. By default, it only encodes double quotes: http://php.net/htmlspecialchars The default mode, ENT_COMPAT, is the backwards compatible mode which only translates the double-quote character and leaves the single-quote untranslated. We've run into issues where we thought our forms were fairly secure, but some people decided to echo input type='string' value='$foo' / type stuff, which works fine if you encapsulate attributes in double quotes, but in single quotes, we found out that anyone who had a single quote in that value would break the page. Now, I typically use a central wrapper function for encoding and decoding, and if it was in use there, sure, I could have thrown in ENT_QUOTES and solved that issue. However, the vast majority of everything uses double quotes, and there is not really a reason to NOT use them. Of course, I put it out there like that to simply push it because it should be appropriate for everyone. You are right though - it WILL work with single quotes (as we can see), but I recommend a single way of doing things to keep things consistent, and it has been the unspoken standard everywhere I've ever looked for markup... (Funny enough, that page has an example with a single quoted attribute) Leave the single quotes for parameters, indexes, code, not attributes - $.02 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quotes vs. Single Quote
On Thu, Aug 5, 2010 at 8:51 PM, Adam Richardson simples...@gmail.com wrote: Tim Bray, who knows a little bit about XML dialects (tongue in cheek), appears to default to the single quote as his delimiter of choice: http://www.tbray.org/ongoing/ Side note, looks like his stuff is auto-generated by something, so it's defined once and replicated many times for templating... but also I do see some attributes with double quotes mixed in, i.e.: div class=employI work for Google, but the opinions expressed here are my own, and no other party necessarily agrees with them.br/ A full disclosure of my professional interests is on the a href='/ongoing/misc/Tim'author/a page. /div h2 id='comments'Contributions/h2 div class=commentspComment feed for span class=oongoing/span:a href=/ongoing/comments.atomimg src=/ongoing/Feed.png alt=Comments feed//a/p a href=/ongoing/ onclick=setActiveStyleSheet('serif'); return false; onkeypress = setActiveStyleSheet('serif'); return false; accesskey=p id=serifSerif/a #xb7; a href=/ongoing/ onclick=setActiveStyleSheet('sans'); return false; onkeypress = setActiveStyleSheet('sans'); return false; accesskey=p id=sansSans-Serif/a I should say also - double quotes helps when using inline JavaScript in attributes too :) add that to my reasons. I just default to double quotes because of history developing things, it just works easier. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php