[Watford] PHP

Yvan Seth watford.lug.org.uk at malignity.net
Sat Dec 1 16:58:03 GMT 2007


<quote who="walt">
> I usually use just a text editor for HTML and JavaScript which are
> very easy to debug in most browsers.  I have no idea how PHP does it.
> There must something behind it that interprets and/or compiles the
> script. 

PHP is entirely interpreted at the server-side.  The usual method being
that the web-server internally (typically with a loaded "module")
executes the PHP interpreter over the "page" before sending the final
generated HTML to the client.  I.e. you have this in index.php on the
server:

    <html>
    <head><title>Silly</title></head>
    <body><?php echo "Hello World"?></body>
    </html>

A web browser "hits" your page and the server reads the above off disc
and runs the PHP engine over it to generate this:

    <html>
    <head><title>Silly</title></head>
    <body>Hello World</body>
    </html>

Which is then sent to the web browser.

> I thought an IDE would help understand it more easily.

I'm not aware of IDEs for PHP that do much beyond syntax highlighting.
Though I rely on vi for all my editing and so I'm pretty clueless when
it comes to these GUI critters :)

> If I use gedit how to I run the script and debug it?  

Two ways:

1. a) You have a page with embedded PHP code: index.php
   b) You have the "php" command, on debian-sarge, for example, this
      comes from the "php4-cli" package.
   c) You execute: php index.php
   d) This spits out the HTML as it would be sent to the web client.

That's pretty ugly though (you get a bunch of HTML dumped to the
screen).  Almost all PHP developers I've seen work with "live" systems:

2. a) You have a web server installed with PHP support.
   b) You put your "index.php" within your web server's document tree.
      (And edit it in-place.)
   c) You visit the "index.php" via the web server with a web browser.
      (And hit shift-refresh to check things while you edit.)

This has the advantage of showing you the actual page as rendered, and
you can examine the HTML using Firefox's syntax highlighted "view
source".  Plus PHP natively generates error messages that render to web
browsers.  (Also, "tail -f <server-error-log>" is an invaluable tool
when developing web apps.)

You don't have to use your "live" website.  Typically you'll
run something like Apache on your local machine and view it from the
same machine with http://localhost/blah/...php

> By the way, this is just a 'retirement project' to keep my brains
> occupied and, maybe, create some web applications in the process. I
> will need MySQL database connections etc so I thought, after a bit of
> research, PHP is just the job.  We'll see; I might be better off
> reverting to MS-Access and VB :-( 

Personally I'm not a fan of PHP, but it is easy to learn and start
running with.  It could also be worth considering "frameworks" like
Django (http://www.djangoproject.com/), which makes it easy to build web
applications quickly (and I like Python).  Of course, this way lies
religious wars.  There's Perl (with, say, Mason), Ruby (Rails!), etc...

HTH
-Yvan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.lug.org.uk/pipermail/watford/attachments/20071201/fe5e56a5/attachment.bin


More information about the Watford mailing list