Jump to content
Larry Ullman's Book Forums

Just Started This Book Today!


Recommended Posts

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

<!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

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

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

  • 1 month later...

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:

 

1180965.jpeg

 

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. :unsure:

 

Edit: Posting an image instad...

Link to comment
Share on other sites

I've always just done echo statements like this:

 

1180965.jpeg

 

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. :unsure:

 

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

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

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

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

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

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

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

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

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

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

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).

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...