100% found this document useful (6 votes)
187 views

Programming PHP 2nd Edition Covers PHP 5 Rasmus Lerdorf 2024 scribd download

Programming

Uploaded by

zyfozouf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
187 views

Programming PHP 2nd Edition Covers PHP 5 Rasmus Lerdorf 2024 scribd download

Programming

Uploaded by

zyfozouf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Download Full ebookname - Read Now at ebookname.

com

Programming PHP 2nd Edition Covers PHP 5 Rasmus


Lerdorf

https://ebookname.com/product/programming-php-2nd-edition-
covers-php-5-rasmus-lerdorf/

OR CLICK BUTTON

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

PHP architect s Zend PHP 5 certification study guide 1st


ed Edition Davey Shafik

https://ebookname.com/product/php-architect-s-zend-
php-5-certification-study-guide-1st-ed-edition-davey-shafik/

ebookname.com

Learning PHP 5 1st Edition David Sklar

https://ebookname.com/product/learning-php-5-1st-edition-david-sklar/

ebookname.com

Multi Tier Application Programming with PHP 1st Edition


David Wall

https://ebookname.com/product/multi-tier-application-programming-with-
php-1st-edition-david-wall/

ebookname.com

Ben Graham Was a Quant Raising the IQ of the Intelligent


Investor Wiley Finance 1st Edition Steven P. Greiner

https://ebookname.com/product/ben-graham-was-a-quant-raising-the-iq-
of-the-intelligent-investor-wiley-finance-1st-edition-steven-p-
greiner/
ebookname.com
Environmental Disasters Natural Recovery and Human
Responses 1st Edition Roger Del Moral

https://ebookname.com/product/environmental-disasters-natural-
recovery-and-human-responses-1st-edition-roger-del-moral/

ebookname.com

How to write essays and dissertations 2nd edition Edition


Nigel Fabb

https://ebookname.com/product/how-to-write-essays-and-
dissertations-2nd-edition-edition-nigel-fabb/

ebookname.com

Learning by Design Building Sustainable Organizations


Management Organizations and Business 1st Edition A. B.
(Rami) Shani
https://ebookname.com/product/learning-by-design-building-sustainable-
organizations-management-organizations-and-business-1st-edition-a-b-
rami-shani/
ebookname.com

Uncertainties in the Estimation of Radiation Risks and


Probability of Disease Causation 1st Edition Ncrp
Publications
https://ebookname.com/product/uncertainties-in-the-estimation-of-
radiation-risks-and-probability-of-disease-causation-1st-edition-ncrp-
publications/
ebookname.com

Older People in Emergencies Considerations for Action and


Policy Development 1st Edition David Hutton

https://ebookname.com/product/older-people-in-emergencies-
considerations-for-action-and-policy-development-1st-edition-david-
hutton/
ebookname.com
Harriet Tubman James A. Mcgowan

https://ebookname.com/product/harriet-tubman-james-a-mcgowan/

ebookname.com
Programming PHP
Other resources from O’Reilly
Related titles Managing and Using MySQL Web Database Applications
MySQL Cookbook™ with PHP and MySQL
PHP Cookbook™ Learning PHP 5
PHP Pocket Reference Upgrading to PHP 5

oreilly.com oreilly.com is more than a complete catalog of O’Reilly books.


You’ll also find links to news, events, articles, weblogs, sample
chapters, and code examples.

oreillynet.com is the essential portal for developers interested in


open and emerging technologies, including new platforms, pro-
gramming languages, and operating systems.

Conferences O’Reilly brings diverse innovators together to nurture the ideas


that spark revolutionary industries. We specialize in document-
ing the latest tools and systems, translating the innovator’s
knowledge into useful skills for those in the trenches. Visit con-
ferences.oreilly.com for our upcoming events.

Safari Bookshelf (safari.oreilly.com) is the premier online refer-


ence library for programmers and IT professionals. Conduct
searches across more than 1,000 books. Subscribers can zero in
on answers to time-critical questions in a matter of seconds.
Read the books on your Bookshelf from cover to cover or sim-
ply flip to the page you need. Try it today for free.
SECOND EDITION

Programming PHP

Rasmus Lerdorf, Kevin Tatroe,


and Peter MacIntyre

Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo


Programming PHP, Second Edition
by Rasmus Lerdorf, Kevin Tatroe, and Peter MacIntyre

Copyright © 2006, 2002 O’Reilly Media, Inc. All rights reserved.


Printed in the United States of America.

Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.

O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (safari.oreilly.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.

Editors: Tatiana Apandi and Allison Randal Cover Designer: Ellie Volckhausen
Production Editor: Matt Hutchinson Interior Designer: David Futato
Production Services: GEX, Inc. llustrators: Robert Romano, Jessamyn Read,
and Lesley Borash

Printing History:
March 2002: First Edition.
April 2006: Second Edition.

Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Programming PHP, the image of a cuckoo, and related trade dress are trademarks
of O’Reilly Media, Inc.

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.

While every precaution has been taken in the preparation of this book, the publisher and authors
assume no responsibility for errors or omissions, or for damages resulting from the use of the
information contained herein.

This book uses RepKover™, a durable and flexible lay-flat binding.

ISBN-10: 0-596-00681-0
ISBN-13: 978-0-596-00681-5
[M] [10/07]
Table of Contents

Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

1. Introduction to PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
What Does PHP Do? 1
A Brief History of PHP 2
Installing PHP 7
A Walk Through PHP 9

2. Language Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Lexical Structure 18
Data Types 25
Variables 32
Expressions and Operators 36
Flow-Control Statements 49
Including Code 57
Embedding PHP in Web Pages 59

3. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Calling a Function 63
Defining a Function 64
Variable Scope 66
Function Parameters 68
Return Values 71
Variable Functions 72
Anonymous Functions 73

v
4. Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Quoting String Constants 74
Printing Strings 78
Accessing Individual Characters 82
Cleaning Strings 82
Encoding and Escaping 83
Comparing Strings 89
Manipulating and Searching Strings 91
Regular Expressions 97
POSIX-Style Regular Expressions 101
Perl-Compatible Regular Expressions 106

5. Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Indexed Versus Associative Arrays 119
Identifying Elements of an Array 120
Storing Data in Arrays 120
Multidimensional Arrays 123
Extracting Multiple Values 123
Converting Between Arrays and Variables 127
Traversing Arrays 128
Sorting 133
Acting on Entire Arrays 138
Using Arrays 140

6. Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Terminology 144
Creating an Object 144
Accessing Properties and Methods 145
Declaring a Class 146
Introspection 153
Serialization 159

7. Web Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164


HTTP Basics 164
Variables 165
Server Information 166
Processing Forms 168
Setting Response Headers 182
Maintaining State 185
SSL 195

vi | Table of Contents
8. Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Using PHP to Access a Database 196
Relational Databases and SQL 198
PEAR DB Basics 199
Advanced Database Techniques 205
Sample Application 211

9. Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Embedding an Image in a Page 225
The GD Extension 226
Basic Graphics Concepts 227
Creating and Drawing Images 228
Images with Text 232
Dynamically Generated Buttons 236
Scaling Images 239
Color Handling 240

10. PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246


PDF Extensions 246
Documents and Pages 246
Text 248

11. XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261


Lightning Guide to XML 261
Generating XML 263
Parsing XML 264
Parsing XML with DOM 277
Parsing XML with SimpleXML 277
Transforming XML with XSLT 278
Web Services 280

12. Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285


Filter Input 285
Escape Output 290
Cross-Site Scripting 293
Session Fixation 294
File Uploads 295
File Access 296
PHP Code 299

Table of Contents | vii


Shell Commands 300
More Information 301
Security Recap 301

13. Application Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302


Code Libraries 302
Templating Systems 303
Handling Output 306
Error Handling 308
Performance Tuning 313

14. Extending PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321


Architectural Overview 321
What You’ll Need 322
Building Your First Extensions 323
The config.m4 File 333
Memory Management 336
The pval/zval Data Type 338
Parameter Handling 342
Returning Values 345
References 349
Global Variables 350
Creating Variables 353
Extension INI Entries 354
Resources 356
Where to Go from Here 358

15. PHP on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359


Installing and Configuring PHP on Windows 359
Writing Portable Code for Windows and Unix 363
Interfacing with COM 366
Interacting with ODBC Data Sources 372

A. Function Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377

B. Extension Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503

viii | Table of Contents


Foreword

Today, PHP is the most widely used programming language on the Web, with over
40 percent of all web applications written in PHP. It is installed on over 22 million
domain servers (source: Netcraft), as shown in Figure F-1. The number of develop-
ers using PHP has now reached over 2.5 million. The community developing PHP is
very impressive, with over 450 CVS committers who wrote a total of 1 million lines
of code. The PHP community is one of the most dynamic, with thousands of people
sharing code, evangelizing about PHP, supporting each other, and creating many
projects such as Wikipedia, Mambo, PHP-Nuke, FUDforum, SugarCRM, and
Horde, just to mention a few.

IBM, Oracle
Endorse PHP
PHP 5.0
Yahoo! • XML, SOAP, OOP 20M
Standardizes • Zend Studio
on PHP

PHP 4 15M
Released
• 1M Internet domains
• Zend Engine
• Zend Founded
Zeek Suraski, 10M
Andi Gutmans
Rasmus develop
Lerdolf PHP 3
develops
PHP/Fl 5M
PHP
internet
domains
1995 1997 1999 2000 2002 2004 2005

Figure F-1. PHP development timeline with usage

Its simplicity is what made PHP so successful. Simplicity equals less code. Develop-
ers and companies have been developing projects with PHP in a fraction of the time
it would take another language.

ix

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
There is an unacknowledged war that goes on every day in the world of programming.
It is a war between the humans and the computer scientists. It is a war between those
who want simple, sloppy, flexible, human ways to write code and those who want
clean, crisp, clear, correct ways to write code. It is the war between PHP and C++/Java.
—Adam Bosworth
Google
The future of PHP looks very bright. Leading platform vendors such as IBM, Oracle,
MySQL, Intel, and, most recently, Red Hat have all endorsed it. The new Collabora-
tion Project initiated by Zend Technologies rallies many leading companies and com-
munity members around new open source initiatives aimed at taking PHP to the next
level by creating an industrial-grade, de facto standard PHP web application develop-
ment and deployment environment. The Project’s first two open initiatives are:
Zend PHP Framework
This is a web application framework that will accelerate and improve the devel-
opment and deployment of mission-critical PHP web applications.
Support for the Eclipse Development platform
Zend is joining the Eclipse Foundation as a Strategic Developer. It will develop,
in collaboration with partners, a PHP IDE based on the Eclipse platform.
Rasmus Lerdorf, the initial creator of the first version of PHP (then called PHP/FI),
and Kevin Tatroe provided the guidelines for this book. The newest author on the
revision project is Peter MacIntyre, a Zend Certified Engineer with more than five
years experience in PHP. Wez Furlong and Chris Shiflett have also contributed to
this book. Wez modernized the “Extending PHP” chapter, and Chris brought his
renowned expertise in updating the “Security” chapter.
This book is a must-have for anybody working with PHP. Some of the most recog-
nizable names in the PHP community have contributed to it. So you know that you
are getting quality information. It covers all of the important PHP topics, plus unique
issues such as extending and securing PHP, and discusses newer features of XML and
Objects and PDO.
—Michel Gerin
Vice President, Marketing
Zend Technologies, Inc., the PHP Company

x | Foreword

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Preface 1

Now more than ever, the Web is a major vehicle for corporate and personal commu-
nications. Web sites carry satellite images of Earth in its entirety, search for life in
outer space, and house personal photo albums, business shopping carts, and prod-
uct lists. Many of those web sites are driven by PHP, an open source scripting lan-
guage primarily designed for generating HTML content.
Since its inception in 1994, PHP has swept the Web and continues its phenomenal
growth with recent endorsements by IBM and ORACLE corporations (to name a
few). Also, the millions of web sites powered by PHP are testament to its popularity
and ease of use. It lies in the sweet spot between Perl/CGI, Active Server Pages (ASP),
and HTML. Everyday people can learn PHP and can build powerful dynamic web
sites with it. Marc Andreessen, chairman of Opsware Inc. and founder of Netscape
Communications, recently described PHP as having replaced Java as the ideal pro-
gramming language for the Web.
The core PHP language (Version 5+) features powerful string- and array-handling
facilities, as well as greatly improved support for object-oriented programming. With
the use of standard and optional extension modules, a PHP application can interact
with a database such as MySQL or Oracle, draw graphs, create PDF files, and parse
XML files. You can write your own PHP extension modules in C—for example, to
provide a PHP interface to the functions in an existing code library. You can even run
PHP on Windows, which lets you control other Windows applications such as Word
and Excel with COM or interact with databases using ODBC.
This book is a guide to the PHP language. When you finish it, you will know how
the PHP language works, how to use the many powerful extensions that come stan-
dard with PHP, and how to design and build your own PHP web applications.

xi

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Audience
PHP is a melting pot of cultures. Web designers appreciate its accessibility and con-
venience, while programmers appreciate its flexibility, power, diversity, and speed.
Both cultures need a clear and accurate reference to the language. If you are a pro-
grammer, then this book is for you. We show the big picture of the PHP language,
and then discuss the details without wasting your time. The many examples clarify
the explanations, and the practical programming advice and many style tips will help
you become not just a PHP programmer, but a good PHP programmer.
If you’re a web designer, you will appreciate the clear and useful guides to specific
technologies, such as XML, sessions, PDF generation, and graphics. And you’ll be
able to quickly get the information you need from the language chapters, which
explain basic programming concepts in simple terms.
This book has been fully revised to cover the latest features of PHP Version 5. We
have endeavored to even talk about some of the features that were still on the draw-
ing board while we were writing this edition. One feature in particular is the new
PDO database interface that was still in development during our writing, but we felt
it important enough to cover in the discussion on databases (Chapter 8).

Assumptions This Book Makes


This book assumes you have a working knowledge of HTML. If you don’t know
HTML, you should gain some experience with simple web pages before you try to
tackle PHP. For more information on HTML, we recommend HTML & XHTML:
The Definitive Guide by Chuck Musciano and Bill Kennedy (O’Reilly).

Contents of This Book


We’ve arranged the material in this book so that you can either read it from start to
finish or jump around to hit just the topics that interest you. The book is divided
into 15 chapters and 2 appendixes, as follows:
Chapter 1, Introduction to PHP
Talks about the history of PHP and gives a lightning-fast overview of what is
possible with PHP programs.
Chapter 2, Language Basics
Is a concise guide to PHP program elements such as identifiers, data types, oper-
ators, and flow-control statements.
Chapter 3, Functions
Discusses user-defined functions, including scope, variable-length parameter
lists, and variable and anonymous functions.

xii | Preface

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Chapter 4, Strings
Covers the functions you’ll use when building, dissecting, searching, and modi-
fying strings in your PHP code.
Chapter 5, Arrays
Details the notation and functions for constructing, processing, and sorting
arrays in your PHP code.
Chapter 6, Objects
Covers PHP’s updated object-oriented features. In this chapter, you’ll learn
about classes, objects, inheritance, and introspection.
Chapter 7, Web Techniques
Discusses web basics such as form parameters and validation, cookies, and sessions.
Chapter 8, Databases
Discusses PHP’s modules and functions for working with databases, using the
PEAR DB library and the MySQL database as examples. Also, the new SQLite
database engine and the new PDO database interface are covered.
Chapter 9, Graphics
Demonstrates how to create and modify image files in a variety of formats from
within PHP.
Chapter 10, PDF
Explains how to create dynamic PDF files from a PHP application.
Chapter 11, XML
Introduces PHP’s updated extensions for generating and parsing XML data.
Chapter 12, Security
Provides valuable advice and guidance for programmers creating secure scripts.
You’ll learn best practices programming techniques here that will help you avoid
mistakes that can lead to disaster.
Chapter 13, Application Techniques
Talks about the advanced techniques that most PHP programmers eventually
want to use, including error handling and performance tuning.
Chapter 14, Extending PHP
An advanced chapter that presents easy-to-follow instructions for building a
PHP extension in C.
Chapter 15, PHP on Windows
Discusses the tricks and traps of the Windows port of PHP. It also discusses the
features unique to Windows, such as COM and ODBC.
Appendix A, Function Reference
A handy quick reference to all the core functions in PHP.
Appendix B, Extension Overview
Describes the standard extensions that ship with PHP.

Preface | xiii

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Conventions Used in This Book
The following typographical conventions are used in this book:
Plain text
Indicates menu titles, menu options, menu buttons, and keyboard accelerators
(such as Alt and Ctrl).
Italic
Indicates new terms, URLs, email addresses, filenames, file extensions, path-
names, directories, and Unix utilities.
Constant width
Indicates commands, options, switches, variables, attributes, keys, functions,
types, classes, namespaces, methods, modules, properties, parameters, values,
objects, events, event handlers, XML tags, HTML tags, macros, the contents of
files, or the output from commands.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values.

This icon signifies a tip, suggestion, or general note.

This icon indicates a warning or caution.

Using Code Examples


This book is here to help you get your job done. In general, you may use the code in
this book in your programs and documentation. You do not need to contact us for
permission unless you’re reproducing a significant portion of the code. For example,
writing a program that uses several chunks of code from this book does not require
permission. Selling or distributing a CD-ROM of examples from O’Reilly books does
require permission. Answering a question by citing this book and quoting example
code does not require permission. Incorporating a significant amount of example
code from this book into your product’s documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the
title, author, publisher, and ISBN. For example: “Programming PHP, Second Edition,
by Rasmus Lerdorf, Kevin Tatroe, and Peter MacIntyre. Copyright 2006 O’Reilly
Media, Inc., 0-596-00681-0.”

xiv | Preface

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
If you feel your use of code examples falls outside fair use or the permission
provided, feel free to contact us at permissions@oreilly.com.

Comments and Questions


Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international or local)
(707) 829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any addi-
tional information. You can access this page at:
http://www.oreilly.com/catalog/progphp2
To comment or ask technical questions about this book, send email to:
bookquestions@oreilly.com
For more information about our books, conferences, Resource Centers, and the
O’Reilly Network, see our web site at:
http://www.oreilly.com

Safari® Enabled
When you see a Safari® Enabled icon on the cover of your favorite tech-
nology book, that means the book is available online through the
O’Reilly Network Safari Bookshelf.
Safari offers a solution that’s better than e-books. It’s a virtual library that lets you
easily search thousands of top tech books, cut and paste code samples, download
chapters, and find quick answers when you need the most accurate, current informa-
tion. Try it for free at http://safari.oreilly.com.

Acknowledgments
Rasmus Lerdorf
I would like to acknowledge the large and wonderfully boisterous PHP community,
without which there would be no PHP today.

Preface | xv

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Kevin Tatroe
Thanks to every individual who ever committed code to PHP or who wrote a line of
code in PHP—you all made PHP what it is today.
To my parents, who once purchased a small LEGO set for a long and frightening
plane trip, beginning an obsession with creativity and organization that continues to
relax and inspire.
Finally, a heaping second spoonful of gratitude to Jennifer and Hadden, who con-
tinue to inspire and encourage me even as I pound out words and code every day.

Peter MacIntyre
I would first like to praise the Lord of Hosts who gives me the strength to face each
day. He created electricity through which I make my livelihood; thanks and praise to
Him for this totally unique and fascinating portion of His creation.
Closer to home, I would like to thank Rasmus for the initial (and continuing) efforts
behind this great language called PHP. I have been using PHP exclusively for many
years now and love its simplicity and logic more each day.
To Kevin, my main coauthor in this edition, thanks for the efforts and desire to stick
with this project to the end. You took on a big task with the “harder” chapters, and
with the help of Wez Furlong and Chris Shiflett we finally pulled it off!
To Allison Randal and Tatiana Apandi at O’Reilly, great patience and professional-
ism came from you both on this project. Thanks for giving me this opportunity and
for working with us from start to finish.
I would also like to thank my friends Mike Burns and Ian Morse, who performed the
almost thankless job of doing the technical editing on this book. My hat goes off to
you both—thanks a lot!
And finally to all those at O’Reilly who so often go unmentioned—I don’t know all
your names, but I know what you have to do to make a book like this finally make it
to the bookshelves. The editing, graphics work, layout, planning, marketing, and so
on all has to be done, and I appreciate your work toward this end.

Dedication
I would like to dedicate my portions of this book to my wonderful wife, Dawn Etta
Riley. She has been supportive of me in my personal endeavors, and although some
of them don’t pay off, she still supports my efforts of the ones that do. I love you,
Dawn, and look forward to the teenage-free years with you. To our children, too, I
would like to dedicate this effort: Daniel Tomas Walker, Charity Margaret Marie
MacIntyre, Michael Peter Walker, and Simon Peter MacIntyre (just to get their
names in print).

xvi | Preface

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Chapter 1 CHAPTER 1
Introduction to PHP

PHP is a simple yet powerful language designed for creating HTML content. This
chapter covers essential background on the PHP language. It describes the nature
and history of PHP; which platforms it runs on; and how to download, install, and
configure it. This chapter ends by showing you PHP in action, with a quick walk-
through of several PHP programs that illustrate common tasks, such as processing
form data, interacting with a database, and creating graphics.

What Does PHP Do?


PHP can be used in three primary ways:
Server-side scripting
PHP was originally designed to create dynamic web content, and it is still best
suited for that task. To generate HTML, you need the PHP parser and a web
server to send the documents. PHP has also become popular for generating XML
documents, graphics, Flash animations, PDF files, and more.
Command-line scripting
PHP can run scripts from the command line, much like Perl, awk, or the Unix
shell. You might use the command-line scripts for system administration tasks,
such as backup and log parsing.
Client-side GUI applications
Using PHP-GTK (http://gtk.php.net), you can write full-blown, cross-platform
GUI applications in PHP.
In this book, we’ll concentrate on the first item, using PHP to develop dynamic web
content.
PHP runs on all major operating systems, from Unix variants including Linux,
FreeBSD, and Solaris to Windows and Mac OS X. It can be used with all leading web
servers, including Apache, Microsoft IIS, and the Netscape/iPlanet servers.

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The language is very flexible. For example, you aren’t limited to outputting just
HTML or other text files—any document format can be generated. PHP has built-in
support for generating PDF files, GIF, JPG, and PNG images, and Flash movies.
One of PHP’s most significant features is its wide-ranging support for databases.
PHP supports all major databases (including MySQL, PostgreSQL, Oracle, Sybase,
and ODBC-compliant databases), and even many obscure ones. With PHP, creating
web pages with dynamic content from a database is remarkably simple.
Finally, PHP provides a library of PHP code to perform common tasks, such as data-
base abstraction, error handling, and so on, with the PHP Extension and Applica-
tion Repository (PEAR). PEAR is a framework and distribution system for reusable
PHP components. You can find out more about it at http://pear.php.net.

A Brief History of PHP


Rasmus Lerdorf first conceived of PHP in 1994, but the PHP that people use today is
quite different from the initial version. To understand how PHP got where it is
today, it is useful to know the historical evolution of the language. Here’s that story,
as told by Rasmus.

The Evolution of PHP


Here is the PHP 1.0 announcement that I posted to the Usenet newsgroup comp.info-
systems.www.authoring.cgi in June 1995:
From: rasmus@io.org (Rasmus Lerdorf)
Subject: Announce: Personal Home Page Tools (PHP Tools)
Date: 1995/06/08
Message-ID: <3r7pgp$aa1@ionews.io.org>#1/1
organization: none
newsgroups: comp.infosystems.www.authoring.cgi

Announcing the Personal Home Page Tools (PHP Tools) version 1.0.

These tools are a set of small tight cgi binaries written in C.


They perform a number of functions including:

. Logging accesses to your pages in your own private log files


. Real-time viewing of log information
. Providing a nice interface to this log information
. Displaying last access information right on your pages
. Full daily and total access counters
. Banning access to users based on their domain
. Password protecting pages based on users' domains
. Tracking accesses ** based on users' e-mail addresses **
. Tracking referring URL's - HTTP_REFERER support
. Performing server-side includes without needing server support for it
. Ability to not log accesses from certain domains (ie. your own)

2 | Chapter 1: Introduction to PHP

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
. Easily create and display forms
. Ability to use form information in following documents

Here is what you don't need to use these tools:

. You do not need root access - install in your ~/public_html dir


. You do not need server-side includes enabled in your server
. You do not need access to Perl or Tcl or any other script interpreter
. You do not need access to the httpd log files

The only requirement for these tools to work is that you have
the ability to execute your own cgi programs. Ask your system
administrator if you are not sure what this means.

The tools also allow you to implement a guestbook or any other


form that needs to write information and display it to users
later in about 2 minutes.

The tools are in the public domain distributed under the GNU
Public License. Yes, that means they are free!

For a complete demonstration of these tools, point your browser


at: http://www.io.org/~rasmus

--
Rasmus Lerdorf
rasmus@io.org
http://www.io.org/~rasmus

Note that the URL and email address shown in this message are long gone. The lan-
guage of this announcement reflects the concerns that people had at the time, such
as password-protecting pages, easily creating forms, and accessing form data on sub-
sequent pages. The announcement also illustrates PHP’s initial positioning as a
framework for a number of useful tools.
The announcement talks only about the tools that came with PHP, but behind the
scenes the goal was to create a framework to make it easy to extend PHP and add
more tools. The business logic for these add-ons was written in C—a simple parser
picked tags out of the HTML and called the various C functions. It was never my
plan to create a scripting language.
So, what happened?
I started working on a rather large project for the University of Toronto that needed
a tool to pull together data from various places and present a nice web-based admin-
istration interface. Of course, I decided that PHP would be ideal for the task, but for
performance reasons, the various small tools of PHP 1 had to be brought together
better and integrated into the web server.
Initially, I made some hacks to the NCSA web server, to patch it to support the core
PHP functionality. The problem with this approach was that as a user, you had to

A Brief History of PHP | 3

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
replace your web-server software with this special, hacked-up version. Fortunately,
Apache was starting to gain momentum around this time, and the Apache API made
it easier to add functionality like PHP to the server.
Over the next year or so, a lot was done and the focus changed quite a bit. Here’s the
PHP Version 2 (PHP/FI) announcement I sent in April 1996:
From: rasmus@madhaus.utcs.utoronto.ca (Rasmus Lerdorf)
Subject: ANNOUNCE: PHP/FI Server-side HTML-Embedded Scripting Language
Date: 1996/04/16
Newsgroups: comp.infosystems.www.authoring.cgi

PHP/FI is a server-side HTML embedded scripting language. It has built-in


access logging and access restriction features and also support for
embedded SQL queries to mSQL and/or Postgres95 backend databases.

It is most likely the fastest and simplest tool available for creating
database-enabled web sites.

It will work with any UNIX-based web server on every UNIX flavour out
there. The package is completely free of charge for all uses including
commercial.

Feature List:

. Access Logging
Log every hit to your pages in either a dbm or an mSQL database.
Having hit information in a database format makes later analysis easier.
. Access Restriction
Password protect your pages, or restrict access based on the refering URL
plus many other options.
. mSQL Support
Embed mSQL queries right in your HTML source files
. Postgres95 Support
Embed Postgres95 queries right in your HTML source files
. DBM Support
DB,DBM,NDBM and GDBM are all supported
. RFC-1867 File Upload Support
Create file upload forms
. Variables, Arrays, Associative Arrays
. User-Defined Functions with static variables + recursion
. Conditionals and While loops
Writing conditional dynamic web pages could not be easier than with
the PHP/FI conditionals and looping support
. Extended Regular Expressions
Powerful string manipulation support through full regexp support
. Raw HTTP Header Control
Lets you send customized HTTP headers to the browser for advanced
features such as cookies.
. Dynamic GIF Image Creation
Thomas Boutell's GD library is supported through an easy-to-use set of
tags.

4 | Chapter 1: Introduction to PHP

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
It can be downloaded from the File Archive at: <URL:http://www.vex.net/php>

--
Rasmus Lerdorf
rasmus@vex.net

This was the first time the term “scripting language” was used. PHP 1’s simplistic
tag-replacement code was replaced with a parser that could handle a more sophisti-
cated embedded tag language. By today’s standards, the tag language wasn’t particu-
larly sophisticated, but compared to PHP 1 it certainly was.
The main reason for this change was that few people who used PHP 1 were actually
interested in using the C-based framework for creating add-ons. Most users were
much more interested in being able to embed logic directly in their web pages for cre-
ating conditional HTML, custom tags, and other such features. PHP 1 users were
constantly requesting the ability to add the hit-tracking footer or send different
HTML blocks conditionally. This led to the creation of an if tag. Once you have if,
you need else as well and from there, it’s a slippery slope to the point where,
whether you want to or not, you end up writing an entire scripting language.
By mid-1997, PHP Version 2 had grown quite a bit and had attracted a lot of users,
but there were still some stability problems with the underlying parsing engine. The
project was also still mostly a one-man effort, with a few contributions here and
there. At this point, Zeev Suraski and Andi Gutmans in Tel Aviv volunteered to
rewrite the underlying parsing engine, and we agreed to make their rewrite the base
for PHP Version 3. Other people also volunteered to work on other parts of PHP,
and the project changed from a one-person effort with a few contributors to a true
open source project with many developers around the world.
Here is the PHP 3.0 announcement from June 1998:
June 6, 1998 -- The PHP Development Team announced the release of PHP 3.0,
the latest release of the server-side scripting solution already in use on
over 70,000 World Wide Web sites.

This all-new version of the popular scripting language includes support


for all major operating systems (Windows 95/NT, most versions of Unix,
and Macintosh) and web servers (including Apache, Netscape servers,
WebSite Pro, and Microsoft Internet Information Server).

PHP 3.0 also supports a wide range of databases, including Oracle, Sybase, Solid,
MySQ, mSQL, and PostgreSQL, as well as ODBC data sources.

New features include persistent database connections, support for the


SNMP and IMAP protocols, and a revamped C API for extending the language
with new features.

"PHP is a very programmer-friendly scripting language suitable for


people with little or no programming experience as well as the
seasoned web developer who needs to get things done quickly. The
best thing about PHP is that you get results quickly," said
Rasmus Lerdorf, one of the developers of the language.

A Brief History of PHP | 5

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
"Version 3 provides a much more powerful, reliable and efficient
implementation of the language, while maintaining the ease of use and
rapid development that were the key to PHP's success in the past,"
added Andi Gutmans, one of the implementors of the new language core.

"At Circle Net we have found PHP to be the most robust platform for
rapid web-based application development available today," said Troy
Cobb, Chief Technology Officer at Circle Net, Inc. "Our use of PHP
has cut our development time in half, and more than doubled our client
satisfaction. PHP has enabled us to provide database-driven dynamic
solutions which perform at phenomenal speeds."

PHP 3.0 is available for free download in source form and binaries for
several platforms at http://www.php.net/.

The PHP Development Team is an international group of programmers who


lead the open development of PHP and related projects.

For more information, the PHP Development Team can be contacted at


core@php.net.

After the release of PHP 3, usage really started to take off. Version 4 was prompted
by a number of developers who were interested in making some fundamental
changes to the architecture of PHP. These changes included abstracting the layer
between the language and the web server, adding a thread-safety mechanism, and
adding a more advanced, two-stage parse/execute tag-parsing system. This new
parser, primarily written by Zeev and Andi, was named the Zend engine. After a lot
of work by a lot of developers, PHP 4.0 was released on May 22, 2000.
Since that release, there have been a few minor releases of PHP 4, with the latest ver-
sion as of this writing being 4.3.11. As this book goes to press, PHP Version 5 has
been released for some time. There have already been a few minor ‘dot’ releases, and
the stability of this current version is quite high. As you will see in this book, there
have been some major advances made in this version of PHP. XML, object orienta-
tion, and SQLite are among the major updates. Many other minor changes, function
additions, and feature enhancements have also been incorporated.

The Growth of PHP


Figure 1-1 shows the growth of PHP as measured by the usage numbers collected by
Netcraft (http://www.netcraft.com) since January 2000. This figure shows the total
number of unique IP addresses that report they are using Apache with the PHP mod-
ule enabled (PHP: 19,720,597 Domains, 1,310,181 IP Addresses). The slight dip at
the end of 2001 reflects the demise of a number of dot-coms that disappeared from
the Web. The overall number of servers that Netcraft found also went down for the
first time during this period. You can see an update of this chart for yourself at any
time by accessing this web address: http://www.php.net/usage.php.

6 | Chapter 1: Introduction to PHP

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Figure 1-1. The growth of PHP usage since 2000

Installing PHP
PHP is available for many operating systems and platforms. The most common
setup, however, is to use PHP as a module for the Apache web server on a Unix
machine. This section briefly describes how to install Apache with PHP. If you’re
interested in running PHP on Windows, see Chapter 15, which explains many of
your options for that operating system.
To install Apache with PHP, you’ll need a Unix machine with an ANSI-compliant C
compiler, and around 10 MB of available disk space for source and object files.
You’ll also need Internet access to fetch the source code for PHP and Apache.
Start by downloading the source distributions of PHP and Apache. The latest files are
always available from the web sites for the respective tools. Since there are so many
options on installation, we are showing here the generic installation instructions for a
Linux server as shown on the PHP web site at http://ca3.php.net/manual/en/install.
unix.php. You will have to replace the xxx signifier in the following steps with the
version of the software that you choose to install.

Although Apache has a Version 2.x you may find that it is more adept
at serving PHP with Version 1.3.xx, so generally we will be using the
1.3.xx version throughout this book.

1. gunzip apache_xxx.tar.gz
2. tar -xvf apache_xxx.tar

Installing PHP | 7

This is the Title of the Book, eMatter Edition


Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Discovering Diverse Content Through
Random Scribd Documents
production of carbonic oxide or carbonic acid, you increase the production of smoke. You
must with coal fuel either have carbonic acid or oxide, or else black smoke.
“Which is the least noxious?” he was asked, and answered, “As far as regards health,
carbonic acid and carbonic oxide are most noxious to health; but it is not so much a question
of health as of cleanliness and comfort, because I believe that this town is as healthy as
other places where there are not these fires.
“It is partly the impure coal gas evolved after the fresh charge of coal which originates the
smokes, when not properly supplied with air; but it is a very mixed question. When a fresh
charge of coal is put upon the fire, a great quantity of evaporable matter, which would be
called impure coal gas according to the language of the question, is produced; and as that
matter travels on in the heated place, if there be a sufficient supply of air, both the hydrogen
and the carbon are entirely burnt. But if there be an insufficient supply of air, the hydrogen is
taken possession of first, and the carbon is set free in its black and solid form; and if that
goes into the cool part of the chimney before fresh air gets to it, that carbon is so carried out
into the atmosphere and is the smoke in question. Generally speaking, the great rush of
smoke is when coal is first put on the fire; and that from the want of a sufficient supply of
oxygen at the right time, because the carbon is cooled so low as not to take fire.”
This eminent chemist stated also that there was no difference in the ultimate chemical effect
upon the air between a wood fire and a coal fire, but with wood there was not so much
smoke set free in the heated place, which caused a difference in the gaseous products of
wood combustion and of coal combustion. He thought that perhaps wood was the fuel which
would be most favourable to health as affecting the atmosphere, inasmuch as it produced
more water, and less carbonic acid, as the product of combustion.
What may be called the peculiarities of a smoky and sooty atmosphere are of course more
strongly developed in London than elsewhere, as the following curious statements show:—
Dr. Reid, in describing metropolitan smoke, spoke of “those black portions of soot that every
one is familiar with, which annoy us, for instance, at the Houses of Parliament to such an
extent that I have been under the necessity of putting up a veil, about 40 feet long and 12
feet deep, on which, on a single evening, taking the worst kind of weather for the production
of soot, we can count occasionally 200,000 visible portions of soot excluded at a single
sitting. We count with the naked eye the number of pieces entangled upon a square inch. I
have examined the amount deposited on different occasions in different parts of London at
the tops of some houses; and on one occasion at the Horse Guards the amount of soot
deposited was so great, that it formed a complete and continuous film, so that when I walked
upon it I saw the impression of my foot left as distinctly on that occasion as when snow lies
upon the ground. The film was exceedingly thin, but I could discover no want of continuity.
On other occasions I have noticed in London that the quantity that escapes into individual
houses is so great that in a single night I have observed a mixture of soot and of hoar frost
collecting at the edge of the door, and forming a stripe three-quarters of an inch in breadth,
and bearing an exact resemblance to a pepper and salt grey cloth. Those that I refer to are
extreme occasions.”
Mr. Booth mentioned, that one of the gardeners of the Botanic Garden in the Regent’s-park,
could tell the number of days sheep had been in the park from the blackness of their wool,
its oleaginous power retaining the black.
Dr. Ure informed the Committee that a column of smoke might be seen extending in different
directions round London, according to the way of the wind, for a distance of from 20 to 30
miles; and that Sir William Herschel had told him that when the wind blew from London he
could not use his great telescope at Slough.
It was stated, moreover, that when a respirator is washed, the water is rendered dirty by the
particles of soot adhering to the wire gauze, and which, but for this, would have entered the
mouth.
Professor Brande said, on the subject of the public health being affected by smoke, “I cannot
say that my opinion is that smoke produces any unhealthiness in London; it is a great
nuisance certainly; but I do not think we have any good evidence that it produces disease of
any kind.”
“This Committee,” said Mr. Beckett, “have been told that, by the mechanical effects of smoke
upon the chest and lungs, disease takes place; that is, by swallowing a certain quantity of
smoke the respiratory organs are injured; can you give any opinion upon that?”—“One would
conceive,” replied the Professor, “that that is the case; but when we compare the health of
London with that of any other town or place where they are comparatively free or quite free
from smoke, we do not find that difference which we should expect in regard to health.”
Mr. E. Solly, lecturer on chemistry at the Royal Institution, expressed his opinion of the effect
of smoke upon the health of towns:—
“My impression is,” he said, “that it produces decided evil in two or three ways: first,
mechanically; the solid black carbonaceous matter produces a great deal of disease; it
occasions dirt amongst the lower orders, and, if they will not take pains to remove it, it
engenders disease. If we could do away the smoke nuisance, I believe a great deal of that
disease would be put an end to. But there is another point, and that is, the bad effects
produced by the gases, sulphurous acid and other compounds of that nature, which are given
out. If we do away with smoke, we shall still have those gases; and I have no doubt that
those gases produce a great part of the disease that is produced by smoke.”
On the other hand Dr. Reid thought that smoke was more injurious from the dirt it created
than from causing impurity in the atmosphere, although “it was obvious enough that the
inspiration of a sooty atmosphere must be injurious to persons of a delicate constitution.” Dr.
Ure pronounced smoke, in the common sense of visible black smoke, unwholesome, but “not
so eminently as the French imagine.”
Many witnesses stated their conviction that where poor people resided amongst smoke, they
felt it impossible to preserve cleanliness in their persons or their dwellings, and that made
them careless of their homes and indifferent to a decency of appearance, so that the public-
house, and places where cleanliness and propriety were in no great estimation, became
places of frequent resort, on the plain principle that if a man’s home were uncomfortable, he
was not likely to stay in it.
“I think,” said Mr. Booth, “one great effect of the evil of smoke is upon the dwellings of the
poor; it renders them less attentive to their personal appearance, and, in consequence, to
their social condition.”
It was also stated that there were “certain districts inhabited by the poor, where they will not
hang out their clothes to be cleansed; they say it is of no use to do it, they will become dirty
as before, and consequently they do not have their clothes washed.” The districts specified as
presenting this characteristic are St. George’s-in-the East and the neighbourhood of Old-
street, St. Luke’s.
It must not be lost sight of, that whatever evils, moral or physical, without regarding merely
pecuniary losses, are inflicted by the excess of smoke, they fall upon the poor, and almost
solely on the poor. It is the poor who must reside, as was said, and with a literality not often
applicable to popular phrases, “in the thick of it,” and consequently there must either be
increased washing or increased dirt.
To effect the mitigation of the nuisance of smoke, two points were considered:—
A. The substitution of some other material, containing less bituminous matter,
for the “Newcastle coal.”
B. The combustion of the smoke, before its emission into the atmospheric air,
by means of mechanical contrivances founded on scientific principles.
As regards the first consideration (A) it was recommended that anthracite, or stone Welsh
coal, which is a smokeless fuel, should be used instead of the Newcastle coal. This coal is
almost the sole fuel in Philadelphia, a city of Quaker neatness beyond any in the United
States of North America, and sometimes represented as the cleanest in the world. The
anthracite coal is somewhat dearer than Newcastle coal in London, but only in a small
degree.
Coke was also recommended as a substitute for coal in private dwellings.
“Are you of opinion,” Dr. Reid was asked, “that smoke may be in a great measure prevented
by extending the use of gas and coke?” He answered, “In numerous cities, where large
quantities of gas are produced, coke is very frequently the principal fuel of the poor, and the
difficulty of lighting that coke, and the difficulty of having heat developed by it in sufficient
quantity, necessarily led me to look at the construction of the fire-places adapted for it. And
on a general review of the question, I do entertain the opinion, that if education were more
extended amongst the humblest classes with respect to the economy of their own fireside (I
mean, literally, the fire-place, at present), and if gas were greatly extended, so that they did
not drain the coal of the gas-works of the last dregs of gaseous matter, which are of very
little use as gas, and more to be considered as adding to the bulk for sale than as valuable
gas, that a coke might be left which would be easily accendible, which would be economical,
and which, if introduced into fire-places where an open fire is desired, would entirely remove
the necessity of sweeping chimneys even with machines, and would at the same time give as
economical a fire as any ordinary fire-place can produce, for an ordinary coal fire rarely is
powerful in its calorific emanations till the mass of gas has been expelled, and we see the
cherry-red fire. The amount of gas that has escaped previously to the production or coking of
the fire, is the gas that is valuable in a manufactory, and if therefore the individual consumer
could have, not the hard-burnt stony coke, but the soft coke, in the condition that would give
at once a cherry-red fire, we should attain the two great objects—of economising gas, and at
the same time of having a lively cheerful fire. Then this led me to look particularly at the
price of a gas lamp for a poor man. In a poor man’s family, where the breakfast, the tea and
dinner, require the principal attention, and he has some plain cooking utensils, in the heat of
summer I believe that he will produce as much heat as he wants for those purposes from a
single burner, which can be turned on and left all day, which shall not risk any boiling over,
and by having this pure heat directed to the object to be warmed, instead of having a heavy
iron grate, this plan would, if gas were generally introduced even into the humblest
apartments, prove a great source of economy in summer.”
Dr. Reid also told the Committee that there was a great prejudice against the use of coke,
many persons considering that it produced a sulphurous smell; but as all ordinary coal coked
itself, or became coke in an open fire, and was never powerfully calorific till it became coke,
the prejudice would die away.
Very little is said in the Report about the smoke of private houses; an allusion, however, is
made to that portion of the investigation:—“Your Committee have received the most
gratifying assurances of the confident hope entertained by several of the highest scientific
authorities examined by them, that the black smoke proceeding from fires in private
dwellings, and all other places, may eventually be entirely prevented, either by the adoption
of stoves and grates formed for a perfect combustion of the common bituminous coal, or by
the use of coke, or of anthracite; but they are of opinion that the present knowledge on that
subject is not such as to justify any legislative interference with these smaller fires.”
“I should, in prospect,” Professor Faraday said to the Committee, “look forward to the
possibility of a great reduction of the smoke from coal fires in houses; but my impression is,
that, in the present state of things, it would be tyrannical to determine that that must be
done which at present we do not know can be done. Still, I think there is reason to believe
that it can be effected in a very high degree.”
Dr. Ure also thought that to extend any smoke enactment to private dwellings might be
tyrannical in the present state of the chimneys, but he had no doubt that smoke might be
consumed in fires in private dwellings.

Such, then, are the causes and remedies for smoke, and consequently of soot, for smoke, or
rather opaque smoke, consists, as we have seen, of merely the gases of combustion with
minute particles of carbon diffused throughout them; and as smoke is the result of the
imperfect burning of our coals, it follows that chimney-sweepers are but a consequence of
our ignorance, and that, as we grow wiser in the art of economising our fuel, we shall be
gradually displacing this branch of labourers—the means of preventing smoke being simply
the mode of displacing the chimney-sweepers—and this is another of the many facts to teach
us that not only are we doubling our population in forty years, but we are likewise learning
every year how to do our work with a less number of workers, either by inventing some piece
of mechanism that will enable one “hand” to do as much as one hundred, or else doing away
with some branch of labour altogether. Here lies the great difficulty of the time. A new
element—science, with its offspring, steam—has been introduced into our society within the
last century, decreasing labour at a time when the number of our labourers has been
increasing at a rate unexampled in history; and the problem is, how to reconcile the new
social element with the old social institutions, doing as little injury as possible to the
community.
Suppose, for instance, the “smoke nuisance” entirely prevented, and that Professor Faraday’s
prophecy as to the great reduction of the smoke from coal fires in houses were fulfilled, and
that the expectations of the sanguine and intense Committee, who tell us that they have
“received the most gratifying assurances of the confident hope entertained by several of the
highest scientific authorities, that the black smoke proceeding from fires in private dwellings
and all other places may be eventually entirely prevented,”—suppose that these expectations,
I say, be realized (and there appears to be little doubt of the matter), what is to become of
the 1000 to 1500 “sweeps” who live, as it were, upon this very smoke? Surely the whole
community should not suffer for them, it will be said. True; but unfortunately the same
argument is being applied to each particular section of the labouring class,—and the
labourers make up by far the greater part of the community. If we are daily displacing a
thousand labourers by the annihilation of this process, and another thousand by the
improvement of that, what is to be the fate of those we put on one side? and where shall we
find employment for the hundred thousand new “hands” that are daily coming into existence
among us? This is the great problem for earnest thoughtful men to work out!

But we have to deal here with the chimney-sweepers as they are, and not as they may be in
a more scientific age. And, first, as to the quantity of soot annually deposited at present in
the London chimneys.
The quantity of soot produced in the metropolis every year may be ascertained in the
following manner:—
The larger houses are swept in some instances once a month, but generally once in three
months, and yield on an average six bushels of soot per year. A moderate-sized house,
belonging to the “middle class,” is usually swept four times a year, and gives about five
bushels of soot per annum; while houses occupied by the working and poorer classes are
seldom swept more than twice, and sometimes only once, in the twelvemonth, and yield
about two bushels of soot annually.
The larger houses—the residences of noblemen and the more wealthy gentry—may, then, be
said to produce an average of six bushels of soot annually; the houses of the more
prosperous tradesmen, about five bushels; while those of the humbler classes appear to yield
only two bushels of soot per annum. There are, according to the last returns, in round
numbers, 300,000 inhabited houses at present in the metropolis, and these, from the
“reports” of the income and property tax, may be said to consist, as regards the average
rentals, of the proportions given in the next page.

TABLE SHOWING THE NUMBER OF HOUSES, AT DIFFERENT


AVERAGE RENTALS, THROUGHOUT THE METROPOLIS.
Number of Houses whose Number of Houses whose Number of Houses whose
Average Rental is above Average Rental is above Average Rental is below
£50. £30 and below £50. £30.
Number Number Number
Average Average Average
of of of
Rental. Rental. Rental.
Houses. Houses. Houses.
£ £ £
Hanover-
square, 150 8,795 Poplar 44 6,882 Chelsea 29 7,629
May Fair
St. James’s 128 3,460 Pancras 41 18,731 Wandsworth 29 8,290
St. Martin’s 119 2,323 Hampstead 40 1,719 St. Luke’s 28 6,421
London
117 7,329 Kensington 40 17,292 Lambeth 28 20,520
City
Marylebone 71 15,955 Clerkenwell 38 7,259 Lewisham 27 5,936
Strand 66 3,938 East London 38 4,785 Whitechapel 26 8,832
West
65 2,745 St. Saviour’s 36 4,613Hackney 25 9,861
London
St. Giles’s 60 4,778 Westminster 36 6,647 Camberwell 25 9,417
Holborn 52 4,517St. Olave’s 35 2,365 Rotherhithe 23 2,834
St.
53,840 Islington 35 13,558 George’s, 22 7,005
Southwark
St.
George’s-in- 32 6,151 Newington 22 10,468
the-East
90,002 Greenwich 22 14,423
Shoreditch 20 15,433
Stepney 20 16,346
Bermondsey 18 7,095
Bethnal
9 13,370
Green
163,880
Here we see that the number of houses whose average rental is above 50l. is 53,840; while
those whose average rental is above 30l., and below 50l., are 90,002 in number; and those
whose rental is below 30l. are as many as 163,880; the average rental for all London, 40l.
Now, adopting the estimate before given as to the proportionate yield of soot from each of
these three classes of houses, we have the following items:—
Bushels of
Soot
per Annum.
53,840 houses at a yearly rental above 50l., producing 6 bushels of soot
323,040
each per annum
90,002 houses at a yearly rental above 30l. and below 50l., producing 5
450,010
bushels of soot each per annum
163,880 houses at a yearly rental below 30l., producing 2 bushels of soot
327,760
each per annum
Total number of bushels of soot annually produced throughout London 1,100,810
This calculation will be found to be nearly correct if tried by another mode. The quantity of
soot depends greatly upon the amount of volatile or bituminous matter in the coals used. By
a table given at p. 169 of the second volume of this work it will be seen that the proportion
of volatile matter contained in the several kinds of coal are as follows:—
Cannel or gas coals contain 40 to 60 per cent. of volatile matter.
Newcastle or “house” coals, about 37 per cent.
Lancashire and Yorkshire coals, 35 to 40 per cent.
South Welsh or “steam” coals, 11 to 15 per cent.
Anthracite or “stone” coals, none.
The house coals are those chiefly used throughout London, so that every ton of such coals
contains about 800 lbs. of volatile matter, a considerable proportion of which appears in the
form of smoke; but what proportion and what is the weight of the carbonaceous particles or
soot evolved in a given quantity of smoke, I know of no means of judging. I am informed,
however, by those practically acquainted with the subject, that a ton of ordinary house coals
will produce between a fourth and a half of a bushel of soot[59]. Now there are, say,
3,500,000 tons of coal consumed annually in London; but a large proportion of this quantity
is used for the purposes of gas, for factories, breweries, chemical works, and steam-boats.
The consumption of coal for the making of gas in London, in 1849, was 380,000 tons; so
that, including the quantity used in factories, breweries, &c., we may, perhaps, estimate the
domestic consumption of the metropolis at 2,500,000 tons yearly, which, for 300,000 houses,
would give eight tons per house. And when we remember the amount used in large houses
and in hotels, as well as by the smaller houses, where each room often contains a different
family, this does not appear to be too high an average. Mr. M’Culloch estimates the domestic
consumption at one ton per head, men, women, and children; and since the number of
persons to each house in London is 7·5, this would give nearly the same result. Estimating
the yield of soot to be three-eighths of a bushel per ton, we have, in round numbers,
1,000,000 bushels of soot as the gross quantity deposited in the metropolitan chimneys every
year.
Or, to check the estimate another way, there are 350 master sweepers throughout London. A
master sweeper in a “large way of business” collects, I am informed, one day with another,
from 30 to 40 bushels of soot; on the other hand, a small master, or “single-handed”
chimney-sweeper is able to gather only about 5 bushels, and scarcely that. One master
sweeper said that about 10 bushels a day would, he thought, be a fair average quantity for
all the masters, reckoning one day with another; so that at this rate we should have
1,095,500 bushels for the gross quantity of soot annually collected throughout the
metropolis.
We may therefore assume the aggregate yield of soot throughout London to be 1,000,000
bushels per annum. Now what is done with this immense mass of refuse matter? Of what use
is it?
The soot is purchased from the masters, whose perquisite it is, by the farmers and dealers. It
is used by them principally for meadow land, and frequently for land where wheat is grown;
not so much, I understand, as a manure, as for some quality in it which destroys slugs and
other insects injurious to the crops[60]. Lincolnshire is one of the great marts for the London
soot, whither it is transported by railway. In Hertfordshire, Cambridge, Norfolk, Suffolk,
Essex, and Kent, however, and many other parts, London soot is used in large quantities;
there are persons who have large stores for its reception, who purchase it from the master
sweepers, and afterwards sell it to the farmers and send it as per order, to its destination.
These are generally the manure-merchants, of whom the Post-Office Directory gives 26
names, eight being marked as dealers in guano. I was told by a sweeper in a large way of
business that he thought these men bought from a half to three-quarters of the soot; the
remainder being bought by the land-cultivators in the neighbourhood of London. Soot is often
used by gardeners to keep down the insects which infest their gardens.

The value of the Soot collected throughout London is the next subject to engage our
attention. Many sweepers have represented it as a very curious fact, and one for which they
could advance no sufficient reason, that the price of a bushel of soot was regulated by the
price of the quartern loaf, so that you had only to know that the quartern loaf was 5d. to
know that such was the price of a bushel of soot. This, however, is hardly the case at
present; the price of the quartern loaf (not regarding the “seconds,” or inferior bread), is
now, at the end of December, 1851, 5d. to 6d. according to quality. The price of soot per
bushel is but 5d., and sometimes but 4½d., but 5d. may be taken as an average.
Now 1,000,000 bushels of soot, at 5d., will be found to yield 20,833l. 6s. 8d. per annum. But
the whole of this quantity is not collected by the chimney-sweepers, for many of the poorer
persons seldom have their chimneys swept; and by the table given in another place, it will be
seen that not more than 800,000 bushels are obtained in the course of the year by the
London “sweeps.” Hence we may say, that there are 800,000 bushels of soot annually
collected from the London chimneys, and that this is worth not less than 16,500l. per annum.

The next question is, how many people are employed in collecting this quantity of refuse
matter, and how do they collect it, and what do they get, individually and collectively, for so
doing?
To begin with the number of master and journeymen sweepers employed in removing these
800,000 bushels of soot from our chimneys: according to the Census returns, the number of
“sweeps” in the metropolis in the years 1841 and 1831 were as follows:—
Increase in
Chimney-sweepers. 1841. 1831.
ten years.
Males, 20 years and upwards 619 421 198
„ under 20 years 370 no returns.
Females, 20 years & upwards 44 „
1033

But these returns, such as they are, include both employers and employed, in one confused
mass. To disentangle the economical knot, we must endeavour to separate the number of
master sweepers from the journeymen. According to the Post-Office Directory the master
sweepers amount to no more than 32, and thus there would be one more than 1000 for the
number of the metropolitan journeymen sweepers; these statements, however, appear to be
very wide of the truth.
In 1816 it was represented to the House of Commons, that there were within the bills of
mortality, 200 masters, all—except the “great gentlemen,” as one witness described them,
who were about 20 in number—themselves working at the business, and that they had 150
journeymen and upwards of 500 apprentices, so that there must then have been 850 working
sweepers altogether, young and old.
These numbers, it must be borne in mind, were comprised in the limits of the bills of
mortality 34 years ago. The parishes in the old bills of mortality were 148; there are now in
the metropolis proper 176, and, as a whole, the area is much more densely covered with
dwelling-houses. Taking but the last ten years, 1841 to 1851, the inhabited houses have
increased from 262,737 to 307,722, or, in round numbers, 45,000.
Now in 1811 the number of inhabited houses in the metropolis was 146,019, and in 1821 it
was 164,948; hence in 1816 we may assume the inhabited houses to have been about
155,000; and since this number required 850 working sweepers to cleanse the London
chimneys, it is but a rule of three sum to find how many would have been required for the
same purpose in 1841, when the inhabited houses had increased to 262,737; this, according
to Cocker, is about 1400; so that we must come to the conclusion either that the number of
working sweepers had not kept pace with the increase of houses, or that the returns of the
census were as defective in this respect as we have found them to be concerning the street-
sellers, dustmen, and scavagers. Were we to pursue the same mode of calculation, we should
find that if 850 sweepers were required to cleanse the chimneys of 155,000 houses, there
should be 1687 such labourers in London now that the houses are 307,722 in number.
But it will be seen that in 1816 more than one-half (or 500 out of 850) of the working
chimney-sweepers were apprentices, and in 1841 the chimney-sweepers under 20 years of
age, if we are to believe the census, constituted more than one-third of the whole body (or
370 out of 1033). Now as the use of climbing boys was prohibited in 1842, of course this
large proportion of the trade has been rendered useless; so that, estimating the master and
journeymen sweepers at 250 in 1816, it would appear that about 500 would be required to
sweep the chimneys of the metropolis at present. To these, of course, must be added the
extra number of journeymen necessary for managing the machines. And considering the
journeymen to have increased threefold since the abolition of the climbing boys, we must add
300 to the above number, which will make the sum total of the individuals employed in this
trade to amount to very nearly 800.
By inquiries throughout the several districts of the metropolis, I find that there are altogether
350 master sweepers at present in London; 106 of these are large masters, who seldom go
out on a round, but work to order, having a regular custom among the more wealthy classes;
while the other 244 consist of 92 small masters and 152 “single-handed” masters, who travel
on various rounds, both in London and the suburbs, seeking custom. Of the whole number,
19 reside within the City boundaries; from 90 to 100 live on the Surrey side, and 235 on the
Middlesex side of the Thames (without the City boundaries). A large master employs from 2
to 10 men, and 2 boys; and a small one only 2 men or sometimes 1 man and a boy, while a
single-handed master employs no men nor boys at all, but does all the work himself.
The 198 masters employ among them 12 foremen, 399 journeymen, and 62 boys, or 473
hands, and adding to them the single-handed master-men who work at the business
themselves, we have 823 working men in all; so that, on the whole, there are not less than
between 800 and 900 persons employed in cleansing the London chimneys of their soot.
The next point that presents itself in due order to the mind is, as to the mode of working
among the chimney-sweepers; that is to say, how are the 800,000 bushels of soot collected
from the 300,000 houses by these 820 working sweepers? But this involves a short history of
the trade.
Of the Sweepers of Old, and the Climbing Boys.
Formerly the chimneys used to be cleansed by the house servants, for a person could easily
stand erect in the huge old-fashioned constructions, and thrust up a broom as far as his
strength would permit. Sometimes, however, straw was kindled at the mouth of the chimney,
and in that way the soot was consumed or brought down to the ground by the action of the
fire. But that there were also regular chimney-sweepers in the latter part of the sixteenth
century is unquestionable; for in the days of the First James and Charles, poor Piedmontese,
and more especially Savoyards, resorted to England for the express purpose. How long they
laboured in this vocation is unknown. The Savoyards, indeed, were then the general
showmen and sweeps of Europe, and so they are still in some of the cities of Italy and
France.
As regards the first introduction of English children into chimneys—the establishment of the
use of climbing boys—nothing appears, according to the representations made to Parliament
on several occasions, to be known; and little attention seems to have been paid to the
condition of these infants—some were but little better—until about 1780, when the
benevolent Jonas Hanway, who is said, but not uncontradictedly, to have been the first
person who regularly used an umbrella in the streets of London, called public attention to the
matter. In 1788 Mr. Hanway and others brought a bill into Parliament for the better protection
of the climbing boys, requiring, among other provisions, all master sweepers to be licensed,
and the names and ages of all their apprentices registered. The House of Lords, however,
rejected this bill, and the 28th George III., c. 48, was passed in preference. The chief
alterations sought to be effected by the new Act were, that no sweeper should have more
than six apprentices, and that no boy should be apprenticed at a tenderer age than eight
years. Previously there were no restrictions in either of those respects.
These provisions were, however, very generally violated. By one of those “flaws” or
omissions, so very common and so little creditable to our legislation, it was found that there
was no prohibition to a sweeper’s employing his own children at what age he pleased; and
“some,” or “several,” for I find both words used, employed their sons, and occasionally their
daughters, in chimney climbing at the ages of six, five, and even between four and five
years! The children of others, too, were continually being apprenticed at illegal ages, for no
inquiry was made into the lad’s age beyond the statement of his parents, or, in the case of
parish apprentices, beyond the (in those days) not more trustworthy word of the overseers.
Thus boys of six were apprenticed—for apprenticeship was almost universal—as boys of
eight, by their parents; while parish officers and magistrates consigned the workhouse
orphans, as a thing of course, to the starvation and tyranny which they must have known
were very often in store for them when apprenticed to sweepers.
The following evidence was adduced before Parliament on the subject of infant labour in this
trade:—
Mr. John Cook, a master sweeper, then of Great Windmill-street and Kentish-town, the first
who persevered in the use of the machine years before its use was compulsory, stated that it
was common for parents in the business to employ their own children, under the age of
seven, in climbing; and that as far as he knew, he himself was only between six and seven
when he “came to it;” and that almost all master sweepers had got it in their bills that they
kept “small boys for register-stoves, and such like as that.”
Mr. T. Allen, another master sweeper, was between four and five when articled to an uncle.
THE LONDON SWEEP
[From a Daguerreotype by Beard.]

Mr. B. M. Forster, a private gentleman, a member of the “Committee to promote the


Superseding of Climbing Boys,” said, “Some are put to the employment very young; one
instance of which occurred to a child in the neighbourhood of Shoreditch, who was put to the
trade at four and a quarter years, or thereabouts. The father of a child in Whitechapel told
me last week, that his son began climbing when he was four years and eight months old. I
have heard of some still younger, but only from vague report.”
This sufficiently proves at what infantine years children were exposed to toils of exceeding
painfulness. The smaller and the more slenderly formed the child, the more valuable was he
for the sweeping of flues, the interior of some of them, to be ascended and swept, being but
seven inches square.
I have mentioned the employment of female children in the very unsuitable labour of
climbing chimneys. The following is all the information given on the subject.
Mr. Tooke was asked, “Have you ever heard of female children being so employed?” and
replied, “I have heard of cases at Hadley, Barnet, Windsor, and Uxbridge; and I know a case
at Witham, near Colchester, of that sort.”
Mr. B. M. Foster said, “Another circumstance, which has not been mentioned to the
Committee, is, that there are several little girls employed; there are two of the name of
Morgan at Windsor, daughters of the chimney-sweeper who is employed to sweep the
chimneys of the Castle; another instance at Uxbridge, and at Brighton, and at Whitechapel
(which was some years ago), and at Headley near Barnet, and Witham in Essex, and
elsewhere.” He then stated, on being asked, “Do you not think that girls were employed from
their physical form being smaller and thinner than boys, and therefore could get up narrower
flues?” “The reason that I have understood was, because their parents had not a sufficient
number of boys to bring up to the business.” Mr. Foster did not know the ages of these girls.
The inquiry by a Committee of the House of Commons, which led more than any other to the
prohibition of this infant and yet painful labour in chimney-sweeping, was held in 1817, and
they recommended the “preventing the further use of climbing boys in sweeping of
chimneys;” a recommendation not carried into effect until 1832. The matter was during the
interval frequently agitated in Parliament, but there were no later investigations by
Committees.
I will adduce, specifically, the grievances, according to the Report of 1817, of the climbing
boys; but will first present the following extract from the evidence of Mr. W. Tooke, a
gentleman who, in accordance with the Hon. Henry Grey Bennet, M.P., and others, exerted
himself on the behoof of the climbing boys. When he gave his evidence, Mr. Tooke was the
secretary to a society whose object was to supersede the necessity of employing climbing
boys. He said:—
“In the year 1800, the Society for Bettering the Condition of the Poor took up the subject, but
little or nothing appears to have been done upon that occasion, except that the most
respectable master chimney-sweepers entered into an association and subscription for
promoting the cleanliness and health of the boys in their respective services. The Institution
of which I am treasurer, and which is now existing, was formed in February, 1803. In
consequence of an anonymous advertisement, a large meeting was held at the London
Coffee House, and the Society was established; immediate steps were then taken to ascertain
the state of the trade; inspectors were appointed to give an account of all the master
chimney-sweepers within the bills of mortality, their general character, their conduct towards
their apprentices, and the number of those apprentices. It was ascertained, that the total
number of master chimney-sweepers, within the bills of mortality, might be estimated at 200,
who had among them 500 apprentices; that not above 20 of those masters were reputable
tradesmen in easy circumstances, who appeared generally to conform to the provisions of the
Act; and which 20 had, upon an average, from four to five apprentices each. We found about
90 of an inferior class of master chimney-sweepers who averaged three apprentices each,
and who were extremely negligent both of the health, morals, and education of those
apprentices; and about 90, the remainder of the 200 masters, were a class of chimney-
sweepers recently journeymen, who took up the trade because they had no other resource;
they picked up boys as they could, who lodged with themselves in huts, sheds, and cellars, in
the outskirts of the town, occasionally wandering into the villages round, where they slept on
soot-bags, and lived in the grossest filth.”
The grievances I have spoken of were thus summed up by the Parliamentary Committee.
After referring to the ill-usage and hardships sustained by the climbing boys (the figures
being now introduced for the sake of distinctness) it is stated:—
“It is in evidence that (1) they are stolen from” [and sold by] “their parents, and inveigled out
of workhouses; (2) that in order to conquer the natural repugnance of the infants to ascend
the narrow and dangerous chimneys to clean which their labour is required, blows are used;
that pins are forced into their feet by the boy that follows them up the chimney, in order to
compel them to ascend it, and that lighted straw has been applied for that purpose; (3) that
the children are subject to sores and bruises, and wounds and burns on their thighs, knees,
and elbows; and that it will require many months before the extremities of the elbows and
knees become sufficiently hard to resist the excoriations to which they are at first subject.”
1. With regard to the stealing or kidnapping of children—for there was often a difficulty in
procuring climbing boys—I find mention in the evidence, as of a matter, but not a very
frequent matter, of notoriety. One stolen child was sold to a master sweeper for 8l. 8s. Mr. G.
Revely said:—
“I wish to state to the Committee that case in particular, because it comes home to the better
sort of persons in higher life. It seems that the child, upon being asked various questions,
had been taken away: the child was questioned how he came into that situation; he said all
that he could recollect was (as I heard it told at that time) that he and his sister, with another
brother, were together somewhere, but he could not tell where; but not being able to run so
well as the other two, he was caught by a woman and carried away and was sold, and came
afterwards into the hands of a chimney-sweeper. He was not afterwards restored to his
family, and the mystery was never unravelled; but he was advertised, and a lady took charge
of him.
“This child, in 1804, was forced up a chimney at Bridlington in Yorkshire, by a big boy, the
younger boy being apparently but four years old. He fell and bruised his legs terribly against
the grate. The Misses Auckland of Boynton, who had heard of the child, and went to see him,
became interested by his manners, and they took him home with them; the chimney-
sweeper, who perhaps got alarmed, being glad to part with him. Soon after he got to
Boynton, the seat of Sir George Strickland, a plate with something to eat was brought him;
on seeing a silver fork he was quite delighted, and said, ‘Papa had such forks as those.’ He
also said the carpet in the drawing-room was like papa’s; the housekeeper showed him a
silver watch, he asked what sort it was—‘Papa’s was a gold watch;’ he then pressed the
handle and said, ‘Papa’s watch rings, why does not yours?’ Sir George Strickland, on being
told this circumstance, showed him a gold repeater, the little boy pressed the spring, and
when it struck, he jumped about the room, saying, ‘Papa’s watch rings so.’ At night, when he
was going to bed, he said he could not go to bed until he had said his prayers; he then
repeated the Lord’s Prayer, almost perfectly. The account he gave of himself was that he was
gathering flowers in his mamma’s garden, and that the woman who sold him to the sweeper,
came in and asked him if he liked riding? He said, ‘Yes,’ and she told him he should ride with
her. She put him on a horse, after which they got into a vessel, and the sails were put up,
‘and away we went.’ He had no recollection of his name, or where he lived, and was too
young to think his father could have any other name than that of papa. He started whenever
he heard a servant in the family at Boynton called George, and looked as if he expected to
see somebody he knew; on inquiry, he said he had an uncle George, whom he loved dearly.
He says his mamma is dead, and it is thought his father may be abroad. From many things
he says, he seems to have lived chiefly with an uncle and aunt, whom he invariably says
were called Mr. and Mrs. Flembrough. From various circumstances, it is thought impossible he
should be the child of the woman who sold him, his manners being ‘very civilized,’ quite those
of a child well educated; his dialect is good, and that of the south of England. This little boy,
when first discovered, was conjectured to be about four years old, and is described as having
beautiful black eyes and eye-lashes, a high nose, and a delicate soft skin.”
Mr. J. Harding, a master sweeper, had a fellow apprentice who had been enticed away from
his parents. “It is a case of common occurrence,” he said, “for children stolen, to be
employed in this way. Yes, and children in particular are enticed out of workhouses: there are
a great many who come out of workhouses.”
The following cases were also submitted to the Committee:—
“A poor woman had been obliged by sickness to go into an hospital, and while she was there
her child was stolen from her house, taken into Staffordshire, and there apprenticed to a
chimney-sweeper. By some happy circumstance she learned his fate; she followed him, and
succeeded in rescuing him from his forlorn situation. Another child, who was an orphan, was
tricked into following the same wretched employment by a chimney-sweeper, who gave him a
shilling, and made him believe that by receiving it he became his apprentice; the poor boy,
either discovering or suspecting that he had been deceived, anxiously endeavoured to speak
to a magistrate who happened to come to the house in which he was sweeping chimneys,
but his master watched him so closely that he could not succeed. He at last contrived to tell
his story to a blind soldier, who determined to right the poor boy, and by great exertions
succeeded in procuring him his liberty.”
It was in country places, however, that the stealing and kidnapping of children was the most
frequent, and the threat of “the sweeps will get you” was often held out, to deter children
from wandering. These stolen infants, it is stated, were usually conveyed to some distance by
the vagrants who had secured them, and sold to some master sweeper, being apprenticed as
the child of the vendors, for it was difficult for sweepers in thinly-peopled places to get a
supply of climbing boys. It was shown about the time of the Parliamentary inquiry, in the
course of a trial at the Lancaster assizes, that a boy had been apprenticed to a sweeper by
two travelling tinkers, man and woman, who informed him that the child was stolen from
another “traveller,” 80 miles away, who was “too fond of it to make it a sweep.” The price of
the child was not mentioned.
Respecting the sale of children to be apprentices to sweepers, Mr. Tooke was able to state
that, although in 1816, the practice had very much diminished of late, parents in many
instances still sold their children for three, four, or five guineas. This sum was generally paid
under the guise of an apprentice fee, but it was known to be and was called a “sale,” for the
parents, real or nominal, never interfered with the master subsequently, but left the infant to
its fate.
2. I find the following account of the means resorted to, in order to induce, or more
frequently compel, these wretched infants to work.
The boy in the first instance went for a month, or any term agreed upon, “on trial,” or “to see
how he would suit for the business.” During this period of probation he was usually well
treated and well fed (whatever the character of the master), with little to do beyond running
errands, and observing the mode of work of the experienced climbers. When, however, he
was “bound” as an apprentice, he was put with another lad who had been for some time at
the business. The new boy was sent first up the chimney, and immediately followed by the
other, who instructed him how to ascend. This was accomplished by the pressure of the
knees and the elbows against the sides of the flue. By pressing the knees tightly the child
managed to raise his arms somewhat higher, and then by pressing his elbows in like manner
he contrived to draw up his legs, and so on. The inside of the flue presented a smooth
surface, and there were no inequalities where the fingers or toes could be inserted. Should
the young beginner fall, he was sure to light on the shoulders of the boy beneath him, who
always kept himself firmly fixed in expectation of such a mishap, and then the novice had to
commence anew; in this manner the twain reached the top by degrees, sweeping down the
soot, and descended by the same method. This practice was very severe, especially on new
boys, whose knees and elbows were torn by the pressure and the slipping down continually—
the skin being stripped off, and frequently breaking out in frightful sores, from the constant
abrasions, and from the soot and dirt getting into them.
In his evidence before Parliament in 1817 (for there had been previous inquiries), Mr. Cook
gave an account of the training of these boys, and on being asked:—“Do the elbows and
knees of the boys, when they first begin the business, become very sore, and afterwards get
callous, and are those boys employed in sweeping chimneys during the soreness of those
parts?” answered, “It depends upon the sort of master they have got; some are obliged to
put them to work sooner than others; you must keep them a little at it, or they will never
learn their business, even during the sores.” He stated further, that the skin broke generally,
and that the boys could not ascend chimneys during the sores without very great pain. “The
way that I learn boys is,” he continued, “to put some cloths over their elbows and over their
knees till they get the nature of the chimney—till they get a little used to it: we call it padding
them, and then we take them off, and they get very little grazed indeed after they have got
the art; but very few will take that trouble. Some boys’ flesh is far worse than others, and it
takes more time to harden them.” He was then asked:—“Do those persons still continue to
employ them to climb chimneys?” and the answer was: “Some do; it depends upon the
character of the master. None of them of that class keep them till they get well; none. They
are obliged to climb with those sores upon them. I never had one of my own apprentices do
that.” This system of padding, however, was but little practised; but in what proportion it was
practised, unless by the respectable masters, who were then but few in number, the
Parliamentary papers, the only information on the subject now attainable, do not state. The
inference is, that the majority, out of but 20 of these masters, with some 80 or 100
apprentices, did treat them well, and what was so accounted. The customary way of training
these boys, then, was such as I have described; some even of the better masters, whose
boys were in the comparison well lodged and fed, and “sent to the Sunday school” (which
seems to have comprised all needful education), considered “padding and such like” to be
“new-fangled nonsense.”
I may add also, that although the boy carried up a brush with him, it was used but
occasionally, only when there were “turns” or defects in the chimney, the soot being brought
down by the action of the shoulders and limbs. The climber wore a cap to protect his eyes
and mouth from the soot, and a sort of flannel tunic, his feet, legs, and arms being bare.
Some of these lads were surprisingly quick. One man told me that, when in his prime as a
climbing boy, he could reach the top of a chimney about as quickly as a person could go up
stairs to the attics.
The following is from the evidence of Mr. Cook, frequently cited as an excellent master:—
“What mode do you adopt to get the boy to go up the chimney in the first instance?—We
persuade him as well as we can; we generally practise him in one of our own chimneys first;
one of the boys who knows the trade goes up behind him, and when he has practised it
perhaps ten times, though some will require twenty times, they generally can manage it. The
boy goes up with him to keep him from falling; after that, the boy will manage to go up with
himself, after going up and down several times with one under him: we do this, because if he
happens to make a slip he will be caught by the other.
“Do you find many boys show repugnance to go up at first?—Yes, most of them.
“And if they resist and reject, in what way do you force them up?—By telling them we must
take them back again to their father and mother, and give them up again; and their parents
are generally people who cannot maintain them.
“So that they are afraid of going back to their parents for fear of being starved?—Yes; they
go through a deal of hardship before they come to our trade.
“Did you use any more violent means?—Sometimes a rod.
“Did you ever hear of straw being lighted under them?—Never.
“You never heard of any means being made use of, except being beat and being sent home?
—No; no other.
“You are aware, of course, that those means being gentle or harsh must depend very much
upon the character of the individual master?—It does.
“Of course you must know that there are persons of harsh and cruel disposition; have you
not often heard of masters treating their apprentices with great cruelty, particularly the little
boys, in forcing them to go up those small flues, which the boys were unwilling to ascend?—
Yes; I have forced up many a one myself.
“By what means?—By threatenings, and by giving them a kick or a slap.”
It was also stated that the journeymen used the boys with greater cruelty than did the
masters—indeed a delegated tyranny is often the worst—that for very little faults they kicked
and slapped the children, and sometimes flogged them with a cat, “made of rope, hard at
each end, and as thick as your thumb.”
Mr. John Fisher, a master chimney-sweeper, said:—“Many masters, are very severe with their
children. To make them go up the chimneys I have seen them make them strip themselves
naked; I have been obliged myself to go up a chimney naked.”
As respects the cruelties of driving boys up chimneys by kindling straw beneath their feet, or
thrusting pins into the soles of their feet, I find the following statements given on the
authority of B. M. Forster, Esq., a private gentleman residing in Walthamstow:—
“A lad was ordered to sweep a chimney at Wandsworth; he came down after endeavouring to
ascend, and this occurred several times before he gave up the point; at last the journeyman
took some straw or hay, and lighted it under him to drive him up: when he endeavoured to
get up the last time, he found there was a bar across the chimney, which he could not pass;
he was obliged in consequence to come down, and the journeyman beat him so cruelly, to
use his own expression, that he could not stand for a fortnight.
“In the whole city of Norwich I could find only nine climbing boys, two of whom I questioned
on many particulars; one was with respect to the manner in which they are taught to climb;
they both agreed in that particular, that a larger boy was sent up behind them to prick their
feet, if they did not climb properly. I purposely avoided mentioning about pricking them with
pins, but asked them how they did it; they said that they thrust the pins into the soles of
their feet. A third instance occurred at Walthamstow; a man told me that some he knew had
been taught in the same way; I believe it to be common, but I cannot state any more
instances from authority.”
3. On the subject of the sores, bruises, wounds, burns, and diseases, to which chimney-
sweepers in their apprenticeships were not only exposed, but, as it were, condemned, Mr. R.
Wright, a surgeon, on being examined before the Committee, said, “I shall begin with
Deformity. I am well persuaded that the deformity of the spine, legs, arms, &c., of chimney-
sweepers, generally, if not wholly, proceeds from the circumstance of their being obliged not
only to go up chimneys at an age when their bones are in a soft and growing state, but
likewise from their being compelled by their too merciless masters and mistresses to carry
bags of soot (and those very frequently for a great length of distance and time) by far too
heavy for their tender years and limbs. The knees and ancle joints mostly become deformed,
in the first instance, from the position they are obliged to put them in, in order to support
themselves, not only while climbing up the chimney, but more particularly so in that of
coming down, when they rest solely on the lower extremities.
“Sore eyes and eyelids, are the next to be considered. Chimney-sweepers are very subject to
inflammation of the eyelids, and not unfrequently weakness of sight, in consequence of such
inflammation. This I attribute to the circumstance of the soot lodging on the eyelids, which
first produces irritability of the part, and the constantly rubbing them with their dirty hands,
instead of alleviating, increases the disease; for I have observed in a number of cases, when
the patient has ceased for a time to follow the business, and of course the original cause has
been removed, that with washing and keeping clean they were soon got well.
“Sores, for the same reasons, are generally a long time in healing.
“Cancer is another and a most formidable disease, which chimney-sweepers in particular are
liable to, especially that of the scrotum; from which circumstance, by way of distinction, it is
called the ‘chimney-sweeper’s cancer.’ Of this sort of cancer I have seen several instances,
some of which have been operated on; but, in general, they are apt to let them go too far
before they apply for relief. Cancers of the lips are not so general as cancers of the scrotum.
I never saw but two instances of the former, and several of the latter.”
The “chimney-sweep’s cancer” was always lectured upon as a separate disease at Guy’s and
Bartholomew’s Hospitals, and on the question being put to Mr. Wright: “Do the physicians
who are intrusted with the care and management of those hospitals think that disease of
such common occurrence, that it is necessary to make it a part of surgical education?”—he
replied: “Most assuredly; I remember Mr. Cline and Mr. Cooper were particular on that
subject; and having one or two cases of the kind in the hospital, it struck my mind very
forcibly. With the permission of the Committee I will relate a case that occurred lately, which
I had from one of the pupils of St. Thomas’s Hospital; he informed me that they recently had
a case of a chimney-sweeper’s cancer, which was to have been operated on that week, but
the man ‘brushed’ (to use their expression) or rather walked off; he would not submit to the
operation: similar instances of which I have known myself. They dread so much the knife, in
consequence of foolish persons telling them it is so formidable an operation, and that they
will die under it. I conceive without the operation it is death; for cancers are of that nature
that unless you extricate them entirely they will never be cured.”
Of the chimney-sweeper’s cancer, the following statement is given in the Report: “Mr. Cline
informed your Committee by letter, that this disease is rarely seen in any other persons than
chimney-sweepers, and in them cannot be considered as frequent; for during his practice in
St. Thomas’s hospital, for more than 40 years, the number of those could not exceed 20. But
your Committee have been informed that the dread of the operation which it is necessary to
perform, deters many from submitting to it; and from the evidence of persons engaged in the
trade, it appears to be much more common than Mr. Cline seems to be aware of.
“Cough and Asthma.—Chimney-sweepers are, from their being out at all hours and in all
weathers, very liable to cough and inflammation of the chest.
“Burns.—They are very subject to burns, from their being forced up chimneys while on fire,
or soon after they have been on fire, and while over-heated; and however they may cry out,
their inhuman masters pay not the least attention, but compel them, too often with horrid
imprecations, to proceed.
“Stunted growth, in this unfortunate race of the community, is attributed, in a great measure,
to their being brought into the business at a very early age.”

To accidents they were frequently liable in the pursuit of their callings, and sometimes these
accidents were the being jammed or fixed, or, as it was called in the trade, “stuck,” in narrow
and heated flues, sometimes for hours, and until death.
Among these hapless lads were indeed many deaths from accidents, cruelty, privation, and
exhaustion, but it does not appear that the number was ever ascertained. There were also
many narrow escapes from dreadful deaths. I give instances of each:—
“On Monday morning, the 29th of March, 1813, a chimney-sweeper of the name of Griggs,
attended to sweep a small chimney in the brewhouse of Messrs. Calvert and Co., in Upper
Thames-street; he was accompanied by one of his boys, a lad of about eight years of age, of
the name of Thomas Pitt. The fire had been lighted as early as two o’clock the same
morning, and was burning on the arrival of Griggs and his little boy at eight; the fire-place
was small, and an iron pipe projected from the grate some little distance, into the flue; this
the master was acquainted with (having swept the chimneys in the brewhouse for some
years) and therefore had a tile or two taken from the roof, in order that the boy might
descend the chimney. He had no sooner extinguished the fire than he suffered the lad to go
down; and the consequence, as might be expected, was his almost immediate death, in a
state, no doubt, of inexpressible agony. The flue was of the narrowest description, and must
have retained heat sufficient to have prevented the child’s return to the top, even supposing
he had not approached the pipe belonging to the grate, which must have been nearly red-
hot; this, however, was not clearly ascertained on the inquest, though the appearance of the
body would induce an opinion that he had been unavoidably pressed against the pipe. Soon
after his descent, the master, who remained on the top, was apprehensive that something
had happened, and therefore desired him to come up; the answer of the boy was, ‘I cannot
come up, master; I must die here.’ An alarm was given in the brewhouse, immediately, that
he had stuck in the chimney, and a bricklayer who was at work near the spot attended, and
after knocking down part of the brickwork of the chimney, just above the fire-place, made a
hole sufficiently large to draw him through. A surgeon attended, but all attempts to restore
life were ineffectual. On inspecting the body, various burns appeared; the fleshy part of the
legs, and a great part of the feet more particularly, were injured; those parts, too, by which
climbing boys most effectually ascend or descend chimneys, viz., the elbows and knees,
seemed burnt to the bone; from which it must be evident that the unhappy sufferer made
some attempts to return as soon as the horrors of his situation became apparent.”
“In the improvement made some years since by the Bank of England, in Lothbury, a chimney,
belonging to a Mr. Mildrum, a baker, was taken down, but before he began to bake, in order
to see that the rest of the flue was clear, a boy was sent up, and after remaining some time,
and not answering to the call of his master, another boy was ordered to descend from the top
of the flue and to meet him half-way; but this being found impracticable, they opened the
brickwork in the lower part of the flue, and found the first-mentioned boy dead. In the mean
time the boy in the upper part of the flue called out for relief, saying, he was completely
jammed in the rubbish and was unable to extricate himself. Upon this a bricklayer was
employed with the utmost expedition, but he succeeded only in obtaining a lifeless body. The
bodies were sent to St. Margaret’s Church, Lothbury, and a coroner’s inquest, which sat upon
them, returned the verdict—Accidental Death.”
“In the beginning of the year 1808, a chimney-sweeper’s boy being employed to sweep a
chimney in Marsh-street, Walthamstow, in the house of Mr. Jeffery, carpenter, unfortunately,
in his attempt to get down, stuck in the flue and was unable to extricate himself. Mr. Jeffery,
being within hearing of the boy, immediately procured assistance. As the chimney was low,
and the top of it easily accessible from without, the boy was taken out in about ten minutes,
the chimney-pot and several rows of bricks having been previously removed; if he had
remained in that dreadful situation many minutes longer, he must have died. His master was
sent for, and he arrived soon after the boy had been released; he abused him for the
accident, and, after striking him, sent him with a bag of soot to sweep another chimney. The
child appeared so very weak when taken out that he could scarcely stand, and yet this
wretched being, who had been up ever since three o’clock, had before been sent by his
master to Wanstead, which with his walk to Marsh-street made about five miles.”
“In May, 1817, a boy employed in sweeping a chimney in Sheffield got wedged fast in one of
the flues, and remained in that situation near two hours before he could be extricated, which
was at length accomplished by pulling down part of the chimney.”
On one occasion a child remained above two hours in some danger in a chimney, rather than
venture down and encounter his master’s anger. The man was held to bail, which he could
not procure.
As in the cases I have described (at Messrs. Calvert’s, and in Lothbury), the verdict was
usually “Accidental Death,” or something equivalent.
It was otherwise, however, where wilful cruelty was proven.
The following case was a subject of frequent comment at the time:—
“On Friday, 31st May, 1816, William Moles and Sarah his wife, were tried at the Old Bailey for
the wilful murder of John Hewley, alias Haseley, a boy about six years of age, in the month of
April last, by cruelly beating him. Under the direction of the learned judge, they were
acquitted of the crime of murder, but the husband was detained to take his trial as for a
misdemeanor, of which he was convicted upon the fullest evidence, and sentenced to two
years’ imprisonment. The facts, as proved in this case, are too shocking in detail to relate:
the substance of them is, that he was forced up the chimney on the shoulder of a bigger boy,
and afterwards violently pulled down again by the leg and dashed upon a marble hearth; his
leg was thus broken, and death ensued in a few hours, and on his body and knees were
found scars arising from wounds of a much older date.”

This long-continued system of cruelties, of violations of public and private duties, bore and
ripened its natural fruits. The climbing boys grew up to be unhealthy, vicious, ignorant, and
idle men, for during their apprenticeships their labour was over early in the day, and they
often passed away their leisure in gambling in the streets with one another and other
children of their stamp, as they frequently had halfpence given to them. They played also at
“chuck and toss” with the journeymen, and of course were stripped of every farthing. Thus
they became indolent and fond of excitement. When a lad ceased to be an apprentice,
although he might be but 16, he was too big to climb, and even if he got employment as a
journeyman, his remuneration was wretched, only 2s. a week, with his board and lodging.
There were, however, far fewer complaints of being insufficiently fed than might have been
expected, but the sleeping places were execrable: “They sleep in different places,” it was
stated, “sometimes in sheds, and sometimes in places which we call barracks (large rooms),
or in the cellar (where the soot was kept); some never sleep upon anything that can be
called a bed; some do.”
Mr. T. Allen, a master sweep for 22 years, gave the Committee the following account of the
men’s earnings and (what may be called) the General Perquisites of the trade under the
exploded system:—
“If a man be 25 years of age, he has no more than 2s. a week; he is not clothed, only fed
and lodged in the same manner as the boys. The 2s. a week is not sufficient to find him
clothes and other necessaries, certainly not; it is hardly enough to find him with shoe-leather,
for they walk over a deal of ground in going about the streets. The journeyman is able to live
upon those wages, for he gets halfpence given him: supposing he is 16 or 20 years of age,
he gets the boys’ pence from them and keeps it; and if he happens to get a job for which he
receives a 1s., he gets 6d. of that, and his master the other 6d. The boys’ pence are what
the boys get after they have been doing their master’s work; they get a 1d. or so, and the
journeyman takes it from them, and ‘licks’ them if they do not give it up.” [These “jobs,” after
the master’s work had been done, were chance jobs, as when a journeyman on his round
was called on by a stranger, and unexpectedly, to sweep a chimney. Sometimes, by
arrangement of the journeyman and the lad, the proceeds never reached the master’s
pocket. Sometimes, but rarely, such jobs were the journeyman’s rightful perquisite.] “Men,”
proceeds Mr. Allen, “who are 22 and 23 years of age will play with the young boys and win
their money. That is, they get half the money from them by force, and the rest by fraud.
They are driven to this course from the low wages which the masters give them, because
they have no other means to get anything for themselves, not even the few necessaries
which they may want; for even what they want to wash with they must get themselves. As to
what becomes of the money the boys get on May-day, when they are in want of clothes, the
master will buy them, as check shirts or handkerchiefs. These masters get a share of the
money which the boys collect on May-day. The boys have about 1s. or 1s. 6d.; the
journeyman has also his share; then the master takes the remainder, which is to buy the
boys’ clothes and other necessaries, as they say. I cannot exactly tell what the average
amount is that a boy will get on the May-day; the most that my boy ever got was 5s. But I
think that the boys get more than that; I should think they get as much as 9s. or 10s. apiece.
The Christmas-boxes are generally, I believe, divided among themselves (among the boys);
but I cannot say rightly. It is spent in buying silk handkerchiefs, or Sunday shoes, I believe;
but I am not perfectly sure.”
Of the condition and lot of the operatives who were too big to go up chimneys, Mr. J. Fisher,
a master-sweeper, gave the following account:—“They get into a roving way, and go about
from one master to another, and they often come to no good end at last. They sometimes go
into the country, and after staying there some time, they come back again; I took a boy of
that sort very lately and kept him like my own, and let him go to school; he asked me one
Sunday to let him go to school, and I was glad to let him go, and I gave him leave; he
accordingly went, and I have seen nothing of him since; before he went he asked me if I
would let him come home to see my child buried; I told him to ask his school-master, but he
did not come back again. I cannot tell what has become of him; he was to have served me
for twelve months. I did not take him from the parish; he came to me. He said his parents
were dead. The effect of the roving habit of the large boys when they become too large to
climb, is, that they get one with another and learn bad habits from one another; they never
will stop long in any one place. They frequently go into the country and get various places;
perhaps they stop a month at each; some try to get masters themselves, and some will get
into bad company, which very often happens. Then they turn thieves, they get lazy, they
won’t work, and people do not like to employ them lest they should take anything out of their
houses. The generality of them never settle in any steady business. They generally turn loose
characters, and people will not employ them lest they should take anything out of the house.”
The criminal annals of the kingdom bear out the foregoing account. Some of these boys,
indeed, when they attained man’s estate, became, in a great measure, through their skill in
climbing, expert and enterprising burglars, breaking into places where few men would have
cared to venture. One of the most daring feats ever attempted and accomplished was the
escape from Newgate by a sweeper about 15 years ago. He climbed by the aid of his knees
and elbows a height of nearly 80 feet, though the walls, in the corner of the prison-yard,
where this was done, were nearly of an even surface; the slightest slip could not have failed
to have precipitated the sweeper to the bottom. He was then under sentence of death for
highway robbery.
“His name was Whitehead, and he done a more wonderfuller thing nor that,” remarked an
informant, who had been his master. “We was sweeping the bilers in a sugar-house, and he
went from the biler up the flue of the chimney, it was nearly as high as the Monument, that
chimney; I should say it was 30 or 40 feet higher nor the sugar-house. He got out at the top,
and slid down the bare brickwork on the outside, on to the roof of the house, got through an
attic window in the roof, and managed to get off without any one knowing what became of
him. That was the most wonderfullest thing I ever knowed in my life. I don’t know how he
escaped from being killed, but he was always an oudacious feller. It was nearly three months
after afore we found him in the country. I don’t know where they sent him to after he was
brought back to Newgate, but I hear they made him a turnkey in a prison somewhere, and
that he’s doing very well now.” The feat at the sugar-house could be only to escape from his
apprenticeship.
In the course of the whole Parliamentary evidence the sweepers, reared under the old
climbing system, are spoken of as a “short-lived” race, but no statistics could be given. Some
died old men in middle age, in the workhouses. Many were mere vagrants at the time of their
death.
I took the statement of a man who had been what he called a “climbing” in his childhood,
but as he is now a master-sweeper, and has indeed gone through all grades of the business,
I shall give it in my account of the present condition of the sweepers.
Climbing is still occasionally resorted to, especially when repairs are required, “but the
climbing boys,” I was told, “are now men.” These are slight dwarfish men, whose services are
often in considerable request, and cannot at all times be commanded, as there are only
about twenty of them in London, so effectually has climbing been suppressed. These little
men, I was told, did pretty well, not unfrequently getting 2s. or 2s. 6d. for a single job.
As regards the labour question, during the existence of the climbing boys, we find in the
Report the following results:—
The nominal wages to the journeymen were 2s. a week, with board and lodging. The
apprentices received no wages, their masters being only required to feed, lodge, and clothe
them.
The actual wages were the same as the nominal, with the addition of 1s. as perquisites in
money. There were other perquisites in liquor or broken meat.
In the Reports are no accounts of the duration of labour throughout the year, nor can I
obtain from master-sweepers, who were in the business during the old mode, any sufficient
data upon which to found any calculations. The employment, however, seems to have been
generally continuous, running through the year, though in the course of the twelvemonth one
master would have four and another six different journeymen, but only one at a time. The
vagrant propensities of the class is a means of accounting for this.
The nominal wages of those journeymen who resided in their own apartments were generally
14s. a week, and their actual about 2s. 6d. extra in the form of perquisites. Others resided
“on the premises,” having the care of the boys, with board and lodgings and 5s. a week in
money nominally, and 7s. 6d. actually, the perquisites being worth 2s. 6d.
Concerning the general or average wages of the whole trade, I can only present the following
computation.
Mr. Tooke, in his evidence before the House of Commons, stated that the Committee, of
which he was a member, had ascertained that one boy on an average swept about four
chimneys daily, at prices varying from 6d. to 1s. 6d., or a medium return of about 10d. per
chimney, exclusive of the soot, then worth 8d. or 9d. a bushel. “It appears,” he said, “from a
datum I have here, that those chimney-sweepers who keep six boys (the greatest number
allowed by law) gain, on an average, nearly 270l.; five boys, 225l.; four boys, 180l.; three
boys, 135l.; two boys, 90l.; and one boy 45l. (yearly), exclusive of the soot, which is, I
should suppose, upon an average, from half a bushel to a bushel every time the chimney is
swept.”
“Out of the profits you mention,” he was then asked, “the master has to maintain the
boys?”—“Yes,” was the answer, “and when the expenses of house and cellar rent, and the
wages of journeymen, and the maintenance of apprentices, are taken into the account, the
number of master chimney-sweepers is not only more than the trade will support, but
exceeds, by above one-third, what the public exigency requires. The Committee also
ascertained that the 200 master chimney-sweepers in the metropolis were supposed to have
in their employment 150 journeymen and 500 boys.”
The matter may be reduced to a tabular form, expressing the amount in money—for it is not
asserted that the masters generally gained on the charge for their journeymen’s board and
lodging—as follows:—

Expenditure of Master Chimney-Sweepers under the Climbing-Boy


System.
Yearly.
20 journeymen at individual wages, 14s. each weekly £780
30 ditto, say 12s. weekly 936
100 ditto, 10s. ditto 2,600
Board, Lodging, and Clothing of 500 boys, 4s. 6d. weekly 5,850
Rent, 20 large traders, 10s. 520
Do. 30 others, 7s. 546
Do. 150 do., 3s. 6d. 1,365
20 horses (keep), 10s. 520
General wear and tear 200
£13,317
It appears that about 180 of the master chimney-sweepers were themselves working men, in
the same way as their journeymen.
The following, then, may be taken as the—

Yearly Receipts of the Master Sweepers under the Climbing-Boy


System.
Yearly.
Payment for sweeping 624,000 chimneys (4 daily, according to evidence before
£26,000
Parliament, by each of 500 boys), 10d. per chimney, or yearly
Soot (according to same account), say 5d. per chimney 13,000
Total £39,000
Yearly expenditure 13,317
Yearly profit £25,683
This yielded, then, according to the information submitted to the House of Commons Select
Committee, as the profits of the trade prior to 1817, an individual yearly gain to each master
sweeper of 128l.; but, taking Mr. Tooke’s average yearly profit for the six classes of
tradesmen, 270l., 225l., 180l., 135l., 90l., and 45l. respectively, the individual profit averages
above 157l.
The capital, I am informed, would not average above two guineas per master sweeper,
nothing being wanted beyond a few common sacks, made by the sweepers’ wives, and a few
brushes. Only about 20 had horses, but barrows were occasionally hired at a busy time.
In the foregoing estimates I have not included any sums for apprentice fees, as I believe
there would be something like a balance in the matter, the masters sometimes paying
parents such premiums for the use of their children as they received from the parishes for
the tuition and maintenance of others.
Of the morals, education, religion, marriage, &c., of sweepers, under the two systems, I shall
speak in another place.
It may be somewhat curious to conclude with a word of the extent of chimneys swept by a
climbing boy. One respectable master-sweeper told me that for eleven years he had climbed
five or six days weekly. During this period he thought he had swept fifteen chimneys as a
week’s average, each chimney being at least 40 feet in height; so traversing, in ascending
and descending, 686,400 feet, or 130 miles of a world of soot. This, however, is little to what
has been done by a climber of 30 years’ standing, one of the little men of whom I have
spoken. My informant entertained no doubt that this man had, for the first 22 years of his
career, climbed half as much again as he himself had; or had traversed 2,059,200 feet of the
interior of chimneys, or 390 miles. Since the new Act this man had of course climbed less,
but had still been a good deal employed; so that, adding his progresses for the last 9 years to
the 22 preceding, he must have swept about 456 miles of chimney interiors.

Of the Chimney-Sweepers of the Present Day.


The chimney-sweepers of the present day are distinguished from those of old by the use of
machines instead of climbing boys, for the purpose of removing the soot from the flues of
houses.
The chimney-sweeping machines were first used in this country in the year 1803. They were
the invention of Mr. Smart, a carpenter, residing at the foot of Westminster-bridge, Surrey. On
the earlier trials of the machine (which was similar to that used at present, and which I shall
shortly describe), it was pronounced successful in 99 cases out of 100, according to some
accounts, but failing where sharp angles occurred in the flue, which arrested its progress.
“Means have been suggested,” said Mr. Tooke, formerly mentioned, in his evidence before a
Committee of the House of Commons, “for obviating that difficulty by fixed apparatus at the
top of the flue with a jack-chain and pulley, by which a brush could be worked up and down,
or it could be done as is customary abroad, as I have repeatedly seen it at Petersburgh, and
heard of its being done universally on the Continent, by letting down a bullet with a brush
attached to it from the top; but to obviate the inconvenience, which is considerable, from
persons going upon the roof of a house, Mr. John White, junior, an eminent surveyor, has
suggested the expediency of putting iron shutters or registers to each flue, in the roof or
cockloft of each house; by opening which, and working the machine upwards and
downwards, or letting down the bullet, which is the most compendious manner, the chimney
will be most effectually cleansed; and, by its aperture at bottom being kept well closed, it
would be done with the least possible dirt and inconvenience to the family.”
ONE OF THE FEW REMAINING CLIMBING SWEEPS.
[From a Daguerreotype by Beard.]

The society for the supersedence of the labour of climbing boys promoted the adoption of the
machines by all the means in their power, presenting the new instrument gratuitously to
several master sweepers who were too poor to purchase it. Experiments were made and duly
published as to the effectual manner in which the chimneys at Guildhall, the Mansion House,
the then new Custom House, Dulwich College, and in other public edifices, had been
cleansed by the machine. But these statements seem to have produced little effect. People
thought, perhaps, that the mechanical means which might very well cleanse the chimneys of
large public buildings—and it was said that the chimneys of the Custom House were built
with a view to the use of the machine—might not be so serviceable for the same purposes in
small private dwellings. Experiments continued to be made, often in the presence of
architects, of the more respectable sweepers, and of ladies and gentlemen who took a
philanthropic interest in the question, between the years 1803 and 1817, but with little
influence upon the general public, for in 1817 Mr. Smart supposed that there were but 50 or
60 machines in general use in the metropolis, and those, it appeared from the evidence of
several master sweepers, were used chiefly in gentlemen’s houses, many of those gentlemen
having to be authoritative with their servants, who, if not controlled, always preferred the
services of the climbing boys. Most servants had perquisites from the master sweepers, in the
largest and most profitable ways of business, and they seemed to fear the loss of those
perquisites if any change took place.
The opposition in Parliament, and in the general indifference of the people, to the efforts of
“the friends of the climbing boy” to supersede his painful labours by the use of machinery,
was formidable enough, but that of the servants appears to have been more formidable still.
Mr. Smart showed this in his explanations to the Committee. The whole result of his
experience was that servants set their faces against the introduction of the machine,
grumbling if there were not even the appearance of dirt on the furniture after its use. “The
first winter I went out with this machine,” said Mr. Smart, “I went to Mr. Burke’s in Token-
house Yard, who was a friend of mine, with a man to sweep the chimneys, and after waiting
above an hour in a cold morning, the housekeeper came down quite in a rage, that we
should presume to ring the bell or knock at the door; and when we got admittance, she
swore she wished the machine and the inventor at the devil; she did not know me. We swept
all the chimneys, and when we had done I asked her what objection she had to it now; she
said, a very serious one, that if there was a thing by which a servant could get any
emolument, some d——d invention was sure to take it away from them, for that she received
perquisites.”
This avowal of Mr. Burke’s housekeeper, as brusque as it was honest, is typical of the feelings
of the whole class of servants.
The opposition in Parliament, as I have intimated, continued. One noble lord informed the
House of Peers that he had been indisposed of late and had sought the aid of calomel, the
curative influence of which had pervaded every portion of his frame; and that it as far
surpassed the less searching powers of other medicines, as the brush of the climbing boy in
cleansing every nook and corner of the chimney, surpassed all the power of the machinery,
which left the soot unpurged from those nooks and corners.
The House of Commons, however, had expressed its conviction that as long as master
chimney-sweepers were permitted to employ climbing boys, the natural result of that
permission would be the continuance of those miseries which the Legislature had sought, but
which it had failed, to put an end to; and they therefore recommended that the use of
climbing boys should be prohibited altogether; and that the age at which the apprenticeship
should commence should be extended from eight to fourteen, putting this trade upon the
same footing as others which took apprentices at that age.
This resolution became law in 1829. The employment of climbing boys in any manner in the
interior of chimneys was prohibited under penalties of fine and imprisonment; and it was
enacted that the new measure should be carried into effect in three years, so giving the
master sweepers that period of time to complete their arrangements. During the course of
the experiments and inquiry, the sweepers, as a body, seem to have thrown no obstacles, or
very few and slight obstacles, in the way of the “Committee to promote the Superseding of
the Labour of Climbing Boys;” while the most respectable of the class, or the majority of the
respectable, aided the efforts of the Committee.
This manifestation of public feeling probably modified the opposition of the sweepers, and
unquestionably influenced the votes of members of Parliament. The change in the operations
of the chimney-sweeping business took place in 1832, as quietly and unnoticedly as if it were
no change at all.
The machine now in use differs little from that invented by Mr. Smart, the first introduced,
but lighter materials are now used in its manufacture. It has not been found necessary,
however, to complicate its use with the jack-chain and pulley, and bullet with a brush
attached, and the iron shutters or registers in the roof or cockloft, of which Mr. Tooke spoke.
The machine is formed of a series of hollow rods, made of a supple cane, bending and not
breaking in any sinuosity of the flues. This cane is made of the same material as gentlemen’s
walking-sticks. The first machines were made of wood, and were liable to be broken; and to
enable the sweeps on such occasions to recover the broken part, a strong line ran from
bottom to top through the centre of the sticks, which were bored for the purpose, and strung
on this cord. The cane machine, however, speedily and effectually superseded these
imperfect instruments; and there are now none of them to be met with. To the top tube of
the machine is attached the “brush,” called technically “the head,” of elastic whalebone
spikes, which “give” and bend, in accordance with the up or down motion communicated by
the man working the machine, so sweeping what was described to me as “both ways,” up
and down.
Some of these rods, which fit into one another by means of brass screws, are 4 feet 6 inches
long, and diminish in diameter to suit their adjustment. Some rods are but 3 feet 6 inches
long, and 4 feet is the full average length; while the average price at the machine maker’s is
2s. 6d. a rod, if bought separately. The head costs 10s., on an average, if bought separately.
It is seldom that a machine is required to number beyond 17 rods (extending 68 feet), and
the better class of sweepers are generally provided with 17 rods. The cost of the entire
machine, for every kind of chimney-work, when purchased new, as a whole, is, when of good
quality, from 30s. to 5l., according to the number of rods, duplicate rods, &c. Mr. Smart
stated, in 1817, that the average price of one of his machines was then 2l. 3s.
The sweepers who labour chiefly in the poorer localities—and several told me how indifferent
many people in those parts were as to their chimneys being swept at all—rarely use a
machine to extend beyond 40 feet, or one composed of 10 or 11 rods; but some of the
inferior class of sweepers buy of those in a superior way of trade worn machines, at from a
third to a half of the prime cost. These machines they trim up themselves. One portion of the
work, however, they cannot repair or renew—the broken or worn-out brass screws of the
rods, which they call the “ferules.” These, when new, are 1s. each. There were, when the
machine-work was novel, I was informed, street-artizans who went about repairing these
screws or ferules; but their work did not please the chimney-sweepers, and this street-trade
did not last above a year or two.
The rods of the machine, when carefully attended to, last a long time. One man told me that
he was still working some rods which he had worked since 1842 (nine years), with occasional
renewal of the ferules. The head is either injured or worn down in about two years; if not
well made at first, in a year. The diameter of this head or brush is, on the average, 18 inches.
One of my informants had himself swept a chimney of 80 feet, and one of his fellow-workers
had said that he once swept a chimney of 120 feet high; in both cases by means of the
machine. My informant, however, thought such a feat as the 120-feet sweep was hardly
possible, as only one man’s strength can be applied to the machine; and he was of opinion
that no man’s muscular powers would be sufficient to work a machine at a height of 120 feet.
The labour is sometimes very severe; “enough,” one strongly-built man told me, “to make
your arms, head, and heart ache.”
The old-fashioned chimneys are generally 12 by 14 inches in their dimensions in the interior;
and for the thorough sweeping of such chimneys—the opinion of all the sweepers I saw
according on the subject—a head (it is rarely called brush in the trade) of 18 inches diameter
is insufficient, yet they are seldom used larger. One intelligent master sweeper, speaking from
his own knowledge, told me that in the neighbourhood where he worked numbers of houses
had been built since the introduction of the machines, and the chimneys were only 9 inches
square, as regards the interior; the smaller flues are sometimes but 7. These 9-inch
chimneys, he told me, were frequent in “scamped” houses, houses got up at the lowest
possible rate by speculating builders. This was done because the brickwork of the chimneys
costs more than the other portions of the masonry, and so the smaller the dimensions of the
chimneys the less the cost of the edifice. The machines are sometimes as much crippled in
this circumscribed space as they are found of insufficient dimensions in the old-fashioned
chimneys; and so the “scamped” chimney, unless by a master having many “heads,” is not so
cleanly swept as it might be. Chimneys not built in this manner are now usually 9 inches by
14.
In cleansing a chimney with the machine the sweep stands by, or rather in, the fire-place,
having first attached a sort of curtain to the mantle to confine the soot to one spot, the
operator standing inside this curtain. He first introduces the “head,” attached to its proper
rod, into the chimney, “driving” it forward, then screws on the next rod, and so on, until the
head has been driven to the top of the chimney. The soot which has fallen upon the hearth,
within the curtain, is collected into a sack or sacks, and is carried away on the men’s backs,
and occasionally in carts. The whalebone spikes of the head are made to extend in every
direction, so that when it is moved no part of the chimney, if the surface be even, escapes
contact with these spikes, if the work be carefully done, as indeed it generally is; for the
cleaner the chimney is swept of course the greater amount of soot adds to the profit of the
sweeper. One man told me that he thought he had seen in some old big chimneys, a long
time unswept, more soot brought down by the machine than, under similar circumstances as
to the time the chimney had remained uncleansed, would have been done by the climbing
boy.
All the master sweepers I saw concurred in the opinion that the machine was not in all
respects so effective a sweeper as the climbing boy, as it does not reach the recesses, nooks,
crannies, or holes in the chimney, where the soot remains little disturbed by the present
process. This want is felt the most in the cleansing of the old-fashioned chimneys, especially
in the country.
Mr. Cook, in 1817, stated to the Committee that the cleansing of a chimney by a boy or by a
machine occupied the same space of time; but I find the general opinion of the sweepers
now to be that it is only the small and straight chimneys which can be swept with as great
celerity by a machine as by a climber; in all others the lad was quicker by about 5 minutes in
30, or in that proportion.
I heard sweepers represent that the passing of the Act of Parliament not only deprived them
in many instances of the unexpired term of a boy’s apprenticeship in his services as a climber,
but “threw open the business to any one.” The business, however, it seems, was always
“open to any one.” There was no art nor mystery in it, as regarded the functions of the
master; any one could send a boy up a chimney, and collect and carry away the soot he
brought down, quite as readily and far more easily than he can work a machine.
Nevertheless, men under the old system could hardly (and some say they were forbidden to)
embark in this trade unless they had been apprenticed to it; for they were at a loss how to
possess themselves of climbing boys, and how to make a connection. When the machines
were introduced, however, a good many persons who were able to “raise the price” of one
started in the line on their own account. These men have been called by the old hands
“leeks” or “green ’uns,” to distinguish them from the regularly-trained men, who pride
themselves not a little on the fact of their having served seven or eight years, “duly and
truly,” as they never fail to express it. This increase of fresh hands tended to lower the
earnings of the class; and some masters, who were described to me as formerly very
“comfortable,” and some, comparatively speaking, rich, were considerably reduced by it. The
number of “leeks” in 1832 I heard stated, with the exaggeration to which I have been
accustomed when uninformed men, ignorant of the relative value of numbers, have
expressed their opinions, as 1000!
The several classes in the chimney-sweeping trade may be arranged as follows:—
The Master Chimney-Sweepers, called sometimes “Governors” by the journeymen, are
divisible into three kinds:—
The “large” or “high masters,” who employ from 2 to 10 men and 2 boys, and keep
sometimes 2 horses and a cart, not particularly for the conveyance of the soot, but to go into
the country to a gentleman’s house to fulfil orders.
The “small” or “low masters,” who employ, on an average, two men, and sometimes but one
man and a boy, without either horse or cart.
The “single-handed master-men,” who employ neither men nor boys, but do all the work
themselves.
Of these three classes of masters there are two subdivisions.
The “leeks” or “green-uns,” that is to say, those who have not regularly served their time to
the trade.
The “knullers” or “queriers,” that is to say, those who solicit custom in an irregular manner, by
knocking at the doors of houses and such like.
Of the competition of capitalists in this trade there are, I am told, no instances. “We have our
own stations,” one master sweeper said, “and if I contract to sweep a genelman’s house,
here in Pancras, for 25s. a year, or 10s., or anythink, my nearest neighbour, as has men and
machines fit, is in Marrybun; and it wouldn’t pay to send his men a mile and a half, or on to
two mile, and work at what I can—let alone less. No, sir, I’ve known bisness nigh 20 year,
and there’s nothink in the way of that underworking. The poor creeturs as keeps theirselves
with a machine, and nothing to give them a lift beyond it, they’d undertake work at any
figure, but nobody employs or can trust to them, but on chance.” The contracts, I am told,
for a year’s chimney-sweeping in any mansion are on the same terms with one master as
with another.
As regards the Journeymen Chimney-Sweepers there are also three kinds:—
The “foreman” or “first journeyman” sweeper, who accompanies the men to their work,
superintends their labours, and receives the money, when paid immediately after sweeping.
The “journeyman” sweeper, whose duty it is to work the machine, and (where no under-
journeyman, or boy, is kept) to carry the machine and take home the soot.
The “under-journeyman” or “boy,” who has to carry the machine, take home the soot, and
work the machine up the lower-class flues.
There are, besides these, some 20 climbing men, who ascend such flues as the machines
cannot cleanse effectually, and, it must, I regret to say, be added, some 20 to 30 climbing
boys, mostly under eleven years of age, who are still used for the same purpose “on the sly.”
Many of the masters, indeed, lament the change to machine-sweeping, saying that their
children, who are now useless, would, in “the good old times,” have been worth a pound a
week to them. It is in the suburbs that these climbing children are mostly employed.
The hours of labour are from the earliest morning till about midday, and sometimes later.
There are no Houses of Call, trade societies, or regulations among these operatives, but there
are low public-houses to which they resort, and where they can always be heard of.
When a chimney-sweeper is out of work he merely inquires of others in the same line of
business, who, if they know of any one that wants a journeyman, direct their brother
sweeper to call and see the master; but though the chimney-sweepers have no trade
societies, some of the better class belong to sick, and others to burial, funds. The lower class
of sweepers, however, seem to have no resource in sickness, or in their utmost need, but the
parish. There are sweepers, I am told, in every workhouse in London.
There are three modes of payment common among the sweepers:—

1, in money;
2, partly in money and partly in kind; and
3, by perquisites.

The great majority of the masters pay the men they employ from 2s. to 3s., and a few 4s.
and 6s. per week, together with their board and lodging. It may seem that 3s. per week is a
small sum, but it was remarked to me that there are few working men who, after supporting
themselves, are able to save that sum weekly, while the sweepers have many perquisites of
one sort or other, which sometimes bring them in 1s., 2s., 3s., 4s., and occasionally 5s. or
6s., a week additional—a sufficient sum to pay for clothes and washing. The journeymen,
when lodged in the house of the master, are single men, and if constantly employed might,
perhaps, do well, but they are often unemployed, especially in the summer, when there are
not so many fires kept burning. As soon as one of them gets married, or what among them is
synonymous, “takes up with a woman,” which they commonly do when they are able to
purchase some sort of a machine, they set up for themselves, and thus a great number of
the men get to be masters on their own account, without being able to employ any extra
hands. These are generally reckoned among the “knullers;” they do but little business at first,
for the masters long established in a neighbourhood, who are known to the people, and have
some standing, are almost always preferred to those who are strangers or mere beginners.
It was very common, but perhaps more common in country towns than in London, for the
journeymen, as well as apprentices, in this and many other trades to live at the master’s
table. But the board and lodging supplied, in lieu of money-wages, to the journeymen
sweepers, seems to be one of the few existing instances of such a practice in London. Among
slop-working tailors and shoemakers, some unfortunate workmen are boarded and lodged by
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like