Edward Posted March 26, 2012 Share Posted March 26, 2012 I just started this book today, i am on a marathon now to get through it, then i will continue onto the advanced php book! I have finished another php dynamic websites book by Paul Nixon, but only in reading the first pages of this book I'm learning lots of extra points. I paused on the david powers book finished the first section of the book but want to come back to it later on. Link to comment Share on other sites More sharing options...
Edward Posted March 26, 2012 Author Share Posted March 26, 2012 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Predefined Variables</title> </head> <body> <?php # Script 1.5 - predefined.php // Create a shorthand version of the variable names: $file = $_SERVER['SCRIPT_FILENAME']; $user = $_SERVER['HTTP_USER_AGENT']; $server = $_SERVER['SERVER_SOFTWARE']; // Print the name of this script: echo "<p>You are running the file:<br /><b>$file</b>.</p>\n"; // Print the user's information: echo "<p>You are viewing this page using:<br /><b>$user</b></p>\n"; // Print the server's information: echo "<p>This server is running:<br /><b>$server</b>.</p>\n"; ?> </body> </html> I don't understand why you need to have the \n line breaks at the end of the echo statements because when removing them it doesn't make any difference. You are already using a paragraph html p tag so there would already be margin spacing above and below? Or is this done in the sense that you reset your html paragraphs to have zero spacing top and bottom with a css reset, then you need the line break? Link to comment Share on other sites More sharing options...
rob Posted March 26, 2012 Share Posted March 26, 2012 It creates a newline in the source code not the page layout. 1 Link to comment Share on other sites More sharing options...
Edward Posted March 26, 2012 Author Share Posted March 26, 2012 \n linefeed (LF or 0x0A (10) in ASCII) What does this mean? I found it on php.net. Is this a newline or a linefeed and what is the difference what does it do? Link to comment Share on other sites More sharing options...
Edward Posted March 26, 2012 Author Share Posted March 26, 2012 Yes this is not affected even when i have my localhost server running, even if i remove the \n, so i do want to know what the purpose of using them is, when it makes no difference when they are removed from the code, what is the benefit of having them? Link to comment Share on other sites More sharing options...
rob Posted March 26, 2012 Share Posted March 26, 2012 It does affect something it affects the source code layout, which is the whole point of using it, to make source code more readable. 4 Link to comment Share on other sites More sharing options...
Jonathon Posted March 26, 2012 Share Posted March 26, 2012 Rob is correct. Mega useful, nothing worse than horrible source code. 2 Link to comment Share on other sites More sharing options...
Edward Posted March 26, 2012 Author Share Posted March 26, 2012 Thanks guys got it! Link to comment Share on other sites More sharing options...
Edward Posted March 27, 2012 Author Share Posted March 27, 2012 I wanted to add something to this, if you view Ebay's source code you will see its a mess, in the they are not using the \n. I guess that advantage is that it would be hard for an outsider to see what was going on with their code. Dreamweaver has a cool function where you can take the source code from ebay and then clean it up. If you click on Commands -> Apply Source Formatting to the source code, Dreamweaver will tidy up the html for you which can be quite useful. Link to comment Share on other sites More sharing options...
Joel Posted May 9, 2012 Share Posted May 9, 2012 @edward there are also online tools that will format code in a way that's easier to read. Google JavaScript beautifier. Handles HTML code too and there are others too. Link to comment Share on other sites More sharing options...
Antonio Conte Posted May 14, 2012 Share Posted May 14, 2012 It does affect something it affects the source code layout, which is the whole point of using it, to make source code more readable. I've always just done echo statements like this: It works great, but I'm kind of embarrassed now. I've always done like Edward and thought those line breaks did nothing in PHP. Edit: Posting an image instad... Link to comment Share on other sites More sharing options...
Edward Posted May 14, 2012 Author Share Posted May 14, 2012 I've always just done echo statements like this: It works great, but I'm kind of embarrassed now. I've always done like Edward and thought those line breaks did nothing in PHP. Edit: Posting an image instad... I should of been more patient the line breaks were explained a little further up the book, well don't worry Ebay love to omit the line breaks and don't have any problems doing it. Link to comment Share on other sites More sharing options...
Antonio Conte Posted May 14, 2012 Share Posted May 14, 2012 All the large site's do it. To much unnecessary whitespace. For us normal programmers, though, I think we should care about nice code and whitespace. That's why I do my echo's like that. It'll give you nice source code even without line break. (Or I'm applying them myself at least.) Link to comment Share on other sites More sharing options...
Larry Posted May 14, 2012 Share Posted May 14, 2012 Actually, what I would do is have nice source be created (for easier debugging) and then use a compression/minimization tool to send less data to end users. Same thing goes for JavaScript and CSS. Link to comment Share on other sites More sharing options...
Antonio Conte Posted May 14, 2012 Share Posted May 14, 2012 You care to provide some resources? I've previously used some for CSS, but never for PHP, JS or html. Link to comment Share on other sites More sharing options...
Larry Posted May 16, 2012 Share Posted May 16, 2012 Of course. Well, there's no compression or minimization tool for the PHP. There's caching, but that's different. You should also be in the habit of using compression from the server to the browser, but again, that's a different beast. In terms of JavaScript, once I have my code completed, I would run it through JS Minifier or a JS packer, then include that version of the file with the site. You can search online to find command-line or online versions of these. The same goes for HTML. Taking these steps isn't really necessary for all sites, and not something I'd do to sites that change frequently, but when you're talking about the busiest sites, these little differences become huge. Link to comment Share on other sites More sharing options...
HartleySan Posted May 16, 2012 Share Posted May 16, 2012 This is good for minifying CSS and JS: http://refresh-sf.com/yui/ Also, here's a good site about gzipping your HTML, CSS and JS: http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/ Lastly, here's Yahoo's recommendations for speeding up a site: http://developer.yahoo.com/performance/rules.html Link to comment Share on other sites More sharing options...
Antonio Conte Posted May 18, 2012 Share Posted May 18, 2012 when you're talking about the busiest sites, these little differences become huge. Very interested in this topic generally, especially websites that scale like hell. We've had a lot of talk about Ddos attacks here in Norway the last couple of weeks. Some script kiddies has brought down the national bank's website, several online news papers and IT-sites. Then take Facebook. When they released unique usernames, they did so for everybody at once. 200 million users fought over the same unique user names. In effect, they almost asked about getting Ddos'd from their own user, still, the website stayed up! Amazing! Same for images. Over the years, Facebook has gradually decreased the number of access to disk from 16 to 1. There's several other stories about how they have optimized the site over the years, but Facebook is literally coded in PHP, compiled in C#, and use memcached and MySQL. That's just amazing scaling! Facebook has unique content queried for every single user, still they manage astonishing amounts of traffic every single day. The dream job? Working at Facebook! They seem like such an amazing company. Link to comment Share on other sites More sharing options...
Edward Posted May 18, 2012 Author Share Posted May 18, 2012 Facebook Noooooooo! What would be the fun in jumping in at the deep end? I very much doubt we would even get much say in how things would be developed. I personally think designing something new would be far more interesting. I don't see the point in Facebook I neither have an account there or even on Twitter. All these issues with high traffic are solved by all the top ranking sites. Link to comment Share on other sites More sharing options...
Antonio Conte Posted May 19, 2012 Share Posted May 19, 2012 Don't quite agree. That kind of traffic's sky high. I have very little interest in Facebook from a user perspective, but they interest me very much as a developer. Facebook tries to stay open source and has been enchanting several libraries. They have also made a lot of contribution other large IT-companies has benefited from. It's a pretty amazing company once you get over the fact you don't care from a user perspective. Sorry if this starts to get a little bit off-topic btw. We kind of ended up talking performance here. Link to comment Share on other sites More sharing options...
Edward Posted May 19, 2012 Author Share Posted May 19, 2012 Well Google and Youtube both have high traffic, Youtube being owned by Google, so what's the difference. I did figure from the beginning that you had little interest from user perspective. Most people I know don't bother with it, it's mainly for lost people. You can see already the kind of response I had when I made some social posts on this forum, nobody really cares, shows people know what they have to do here, made me realize I needed to get on also. I would like to know how it works also, ive heard of CDN where you can store country specific data related to users of that region. But first we need a site some seo and some users. Link to comment Share on other sites More sharing options...
Antonio Conte Posted May 19, 2012 Share Posted May 19, 2012 Facebook is not really what's important here. I just used them to illustrate my facination. Might as well have used Youtube as the example. What's kind of unique is the growth rate. Both youtube and facebook grow very fast in traffic from the start. It's just amazing how they've handled that, espacially Facebook. Their downtime numbers are incredible regarding the growth! Link to comment Share on other sites More sharing options...
Edward Posted May 20, 2012 Author Share Posted May 20, 2012 They have system architectural staff people to work on different parts of the site. So with any of those companies it's multiple minds not just a mark zuckerberg handling it all himself which would be impossible. A good server company will have people know how to handle the traffic like rackspace.com. Link to comment Share on other sites More sharing options...
Larry Posted May 21, 2012 Share Posted May 21, 2012 I once saw a presentation by one of the engineers at YouTube. In it, the engineer talked about how the speed performance of the site was not nearly as important as how quickly they could make changes to the system. For example, when they realized that no one could upload videos anymore because they'd reached the capacity of how many items could be stored per directory and they needed to rework the storage system NOW. People naturally talk about speed to the end user and how well something scales, but scaling also applies to how quickly developers can make improvements. Similarly, I read a book some time ago in which the author credited his success with a particular site because they could very rapidly implement new features thank to the language they were using (Lisp or Ada, I think). 1 Link to comment Share on other sites More sharing options...
Antonio Conte Posted May 22, 2012 Share Posted May 22, 2012 Very good point. That is also why Facebook is developed in PHP before parsed to C++. https://github.com/facebook/hiphop-php/wiki/ Link to comment Share on other sites More sharing options...
Recommended Posts