index [] · blogentry class, polymorphism, 2 boolean query syntax, 385 boundary characters in...
TRANSCRIPT
567
INDEX
[ ] (square brackets) in regular expressions, 50
A
abstract keyword, 3abstract methods, 353access permissions, views, 223–224aCFB encryption, 504ACID, 238
atomicitynon-transactional tables, 238–239transactional tables, 239–240
consistency, 240–241durability, 247–250foreign keys, 38isolation, 242
levels, 247READ_COMMITTED, 244–245READ_UNCOMMITTED, 245–246REPEATABLE_READ, 242–244replication, 247SERIALIZABLE, 246–247
relational integrity, 35ACLs (Access Control Lists), 473–474Aksyonoff, Andrew, 369algorithms, UDFs, 277aliases, MySQL, 22ALTER ROUTINE privilege, 230alternation in regular expressions, 51AND operator (MySQL), 33anonymous functions, 78ANSII control codes, 523APC (Alternative PHP Cache), 132
confi guration, 132–133installation, 132–133serialization, 135when to use, 138
appending, memcached, 166–167application sample view, 67–69
Archive storage engine, 109–110args key, 544arguments
checking for string, 285functions, in extensions, 331–334type, checking, 274UDFs, 192
ArrayAccess interface, 77–78arrays
accessing, 347–349associative, 70, 348building, 347–349tracking unlinks, 77
associative arrays, 70, 348atomicity (ACID)
non-transactional tables, 238–239transactional tables, 239–240
auditing, 500–501authorization, memcached, 140autoconf, 292
macros, 292automation attacks, 514–515
B
b-tree indexes, 365back-references in regular expressions, 53basic authentication, 461–463Beanstalk, 442bi-directional encoding
mycrypt extension, 503–505XOR Cipher, 501–503
binary, defi nition, 327binary logging, 500
fi le analysis, 256–257replication and, 251
bindings (SOAP), 537–538bison, 308Blackhole storage engine, 108–109
563120bindex.indd 567563120bindex.indd 567 2/18/10 9:12:26 AM2/18/10 9:12:26 AM
COPYRIG
HTED M
ATERIAL
568
blocking sockets – code
blocking sockets, 346BlogEntry class, polymorphism, 2Boolean query syntax, 385boundary characters in regular expressions, 49breaking replication, 261–262breakpoints in debugging, 302–303built-in functions, 335–336built-in rewrite maps, 451bytecode caching, 132
C
CC++ and, 308UDFs, 273Zend engine, 308
C++C and, 308UDFs, 273
C-libraries, UDFs and, 272cache replication, 145caching, 180–188
bytecode, 132cache locality, 171–173cache replication, 145cache status, checking, 135–138catalogue table, 142deterministic, 144fi le system, 145introduction, 131LRU (Least Recently Used), 140memcached, 138–140
authorization, 140consistent hashing, 140replication, 140
non-deterministic, 144opcode, 132page, 145partial page, 145proactive, 145read-through, 141, 216–219session, 145state, 145strategies, 144–145user, enabling, 133write-back, 142write-through caching, 141
_call( ) magic method, 11callback functions, lambda functions, 78
Callback parameter, 81callbacks, read-through caching callback, 165calling methods, 356_callStatic( ) magic method, 11CAPTCHA (Complete Automated Public Turing test to
tell Computers and Humans Apart), 514cardinality, 550–551CAS (check and set), 174–176, 201–202case sensitivity, joins (MySQL), 26–27catalogue table, 142CBC (Cipher Block Chaining) encryption, 504CentOS, memcached installation, 145–146CFB (Cipher-Feedback Mode) encryption, 504character classes (MySQL), 60character sets, 486–487
collations, 487–488ciphers, 502C10K problem, 132class entry, 350class key, 544_CLASS_ magic constant, 8classes
CodeGen_PECL, example, 320–321command-line scripts, 521–522constants, 354defi nition, 350–351EmailValidator, 56–57FileLog, 9–10ForumTopic, 4inheritance, 350–351interfaces
implementing, 7inheritance, 7
LoggingProxy, 13–14methods, magic, 9–11MultitonExample, 12–13namespaces, 350–351Node, defi ning, 3–4Pagination, 75–76SingletonExample, 11–12variables, 3
CLI (Command Line Interface), 312command-line scripts, 517
clientsmemcached, 153PECL/memcached, 162–163
_clone( ) magic method, 11clone keyword, 12closures, 81–83code, critical section, 360
563120bindex.indd 568563120bindex.indd 568 2/18/10 9:12:26 AM2/18/10 9:12:26 AM
569
CodeGen_PECL – data types
CodeGen_PECL, 314classes, example, 320–321constants, defi ning, 318dependencies, 338extensions, as XML documents, 314functions, defi ning, 316–317globals, 318–319INI directives, 318–319interfaces, 321methods, defi ning, 320objects, defi ning, 319properties, defi ning, 320XML fi les, creating, 314–316
Cole, Jeremy, 483collations of character sets, 487–488colored text, 523–524column privileges, 490–491command-line scripts
classes, 521–522CLI, 517color, 523–524creating, 517–524cron jobs, 522–523input
prompting for, 520–521reading, 518–520
shebang, 518commandsCREATE USER, 496DROP USER, 497–498GRANT, 268, 497mysql_secure_installation, 494replication, 261REVOKE, 268, 497SHOW, 491–492SHOW TABLE STATUS, 92SHOW.ENGINES, 89–90
commentsfunctions, 330regular expressions, 49, 54
COMMIT command, implied, 250complex joins (MySQL), 27complex subqueries (MySQL), 47–49compressed tables, MyISAM storage engine, 96concrete decorators, 16CONDITION clause, 229–230conditional rewrite rules, 447–450
exclamation point, 448testing for patterns, 449testing to check fi le or path, 449
conditions, 229–230config.m4 fi le, 310config.w32 fi le, 310consistency (ACID), 240–241consistent hashing, 140constants, 354
CodeGen_PECL, defi ning, 318magic, 8–9MINIT function, 357
constraints, 35NOT NULL, 35–36UNIQUE KEY, 37UNSIGNED, 36
constructors, copy constructors, 329contexts, 343–344cookies, 471–473copy constructor, 329correlated subqueries (MySQL), 46count( ) method, 73countable interface, 73–74CREATE ROUTINE privilege, 230CREATE USER command, 496CREATE VIEW privilege, 223CREDITS fi le, 310critical section, 360cron jobs, 522–523crontab, 522CSRF attack, 511–514CSV (Comma Separated Value), 112CSV storage engine, 112CTR (Counter Mode) encryption, 504cURL, 528–529current( ) method, 72cursors, 229.cvsignore fi le, 310
D
\d shorthand character, 50Danga Interactive, 139data capture
MySQL, 61regular expressions, 53–54
data persistence, Memory storage engine, 103data sources, Sphinx, 376–379data storage, disk, 275data typesENUM, 36–37function defi nitions fi le, 312–313SET, 36–37
563120bindex.indd 569563120bindex.indd 569 2/18/10 9:12:26 AM2/18/10 9:12:26 AM
570
data warehousing – encryption
data warehousingInfiniDB, 124Infobright, 125views, 225
databases, user authentication, 458Day, Eric, 412db_bytes( ) function, 283, 287db_bytes_deinit( ) function, 284db_bytes_init( ) function, 284DealNews, 402debug back-trace, 544debuggers
gdb, 273attaching to running process, 301–302
Microsoft debugger, 273MySQL and, 564–565UDFs, 273
debugging, 543breakpoints, 302–303debug back-trace, 544literal values and, 304MySQL
commands, 564error log, 560–561PROCESSLIST, 562–564slow query log, 561–562
stack traces, creating, 544–545stepping through code, 302–303UDFs, 300–301
DECLARE clause, 229decorating objects, 14decorator pattern, 14–16decrementing, memcached, 168–169default users, new installation, 494defi ning, interfaces, 7delete( ) method, 168DELETE command, triggers, 235–236DELETE statement, 556–558delta indexes, 389–394dependencies, CodeGen_PECL, 338dependent queries, 45derived tables (MySQL), 46–47deriving interfaces, 7design patterns
decorator, 14–16façade, 13–14multiton, 11–13observer, 18–19
proxy, 13–14publisher/subscriber, 18–19singleton, 11–13
destructors, 5deterministic cache, 144Digest Authentication, 507digest authentication, 463–466Digg, 402_DIR_ magic constant, 9directives, rewrite rules, 444RewriteCond, 447
directoriesext, 308main, 308project directory organization, 281–283Zend, 308
disk space, InnoDB storage engine, 99–100disk storage, 275distributed indexes, 373DML statements, Blackhole storage engine, 108drivers, MySQL, 88Drizzle, 124, 126DROP USER command, 497–498dumb server, 140durability (ACID), 247–250
E
eAccelerator, 132confi guration, 133–134installation, 133–134opcode, optimizer, 134serialization, 135when to use, 138
eBay Memory storage engine, 127ECB (Electronic Code Book) encryption, 503elements, unsetting, 77EmailValidator class, 56–57encoding
bi-directionalmycrypt extension, 503–505XOR Cipher, 501–503
single-directional, 505–506encryption
aCFB, 504CBC, 504CFB, 504CTR, 504
563120bindex.indd 570563120bindex.indd 570 2/18/10 9:12:26 AM2/18/10 9:12:26 AM
571
ENFORCE_SAFE_MODE fl ag – foreign keys
ECB, 503mycrypt extension, 503–505nOFB, 504OFB, 504STREAM, 503
ENFORCE_SAFE_MODE fl ag, 342engines, Zend, 308ENUM data type, 36–37envelopes, SOAP requests, 532error handling, memcached, 178–179error log, debugging MySQL, 560–561errors, stack overfl ow, 544errors/warnings, 346–347
values, 346–347escaping quotes, 80events
altering, 267–268creating, 265–266cron and, 264disabling, 267–268dropping, 267–268event scheduler, enabling, 267meta data, 269–270privileges, 268re-enabling, 268
eventual consistency, 402excerpts, 395expert regular expressions, 52–54EXPERIMENTAL fi le, 310EXPLAIN statement, 547–549EXPLAIN syntax, 102expressions. See regular expressionsext directory, 308extensibility, Federated storage engine, 113extensions, 307
CodeGen_PECL, 314as XML documents, 314XML fi les, 314–316
ext_skel, 309functions in
arguments, 331–334built-in functions, 335–336comments, 330defi nitions, 329–331helper functions, 339–340returning values, 334–335standard output, 340
printing, 361source code, 308UNIX/Linux, 308
variables in, 321–329zval, 321–328
ext_skel, 309funtion defi nitions fi le, 309
F
façade design pattern, 13–14factory methods, 17Falcon storage engine
overview, 118parameters, 119tables, 119–120
Federated storage enginecharacteristics, 113–114Federated Server, 116–117fi les, 117read operations, 112standards, 113table creation, 114–115write statements, 112
feet_to_meters( ) function, 274feet_to_meters_deinit( ) function, 274feet_to_meters_init( ) function, 274fetch method, 134fetch worker (Gearman), 430–433fetchall_hash_result( ) method, 299file key, 544_FILE_ magic constant, 8fi le system caching, 145FileLog class, 9–10fi lesconfig.m4, 310config.w32, 310CREDITS, 310.cvsignore, 310EXPERIMENTAL, 310help, generating, 313LICENSE, 316
final keyword, 3Fitzpatrick, Brad, 139, 401fl ags in streams, 341–342fl ex, 308fl ow control (MySQL), 34–35, 230CASE function, 34IF( ) function, 34IFNULL( ) function, 35NULLIF( ) function, 35
foreign keys, 37–40
563120bindex.indd 571563120bindex.indd 571 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
572
ForumTopic class – GearmanClient object
ForumTopic class, 4polymorphism, 2
fstat( ) function, 275FULLTEXT indexes, 365
Boolean mode, 367–368creating, 366issues, 368–369Natural Language mode, 367searches, 366
modifi er values, 366function defi nitions fi leext_skel, 309using, 312–313
function key, 544_Function_ magic constant, 9functions
anonymous functions, 78closures, 81–83CodeGen_PECL, defi ning, 316–317creating dynamically, 79db_bytes( ), 283, 287db_bytes_deinit( ), 284db_bytes_init( ), 284extensions
arguments, 331–334built-in functions, 335–336comments, 330defi nitions, 329–331helper functions, 339–340returning values, 334–335
feet_to_meters( ), 274feet_to_meters_deinit( ), 274feet_to_meters_init( ), 274fstat( ), 275hashing functions, 506helper functions, 339–340init( ), 285lambda functions, 65, 78lambda-style, 78–81lstat( ), 290MATCH( ), 366memcached, 191–192MINIT, 350, 357PHP API functions, consuming, 336–338php_printf, 340, 361serialize( ), 9setToCache( ), 184sprintf( ), 290standard output, 340stat( ), 275
stored, 226stream functions, 341–343thread-safe, 273user defi ned (See UDFs (user defi ned functions))zend_parase_parameters, 334
G
gcc, 308gdb debugger, 273
running process, attaching to, 301–302GDB (GNU Debugger), 564Gearman, 142, 144
DealNews, 402Digg, 402eventual consistency, 402Gearman MySQL UDFs, 407–409
gman_do( ), 408gman_servers_set( ), 407–408gman_sum( ), 408–409
gearmandinstallation, 404running, 406–407
installationGearman MySQL UDFs, 405–406gearmand, 404job server, 404PECL/Gearman, 404–405
job server, running, 406–407language independence, 412Livejournal and, 401, 402map/reduce operations, 403Narada and, 412overview, 402–404PHP and, 409–412SixApart, 402workers
fetch, 430–433index, 434–435insert, 429–430running, 440search, 433–434
Xing.com, 402Yahoo!, 402
Gearman MySQL UDFs, 272gman_do( ), 408gman_servers_set( ), 407–408gman_sum( ), 408–409installation, 405–406
GearmanClient object, 410
563120bindex.indd 572563120bindex.indd 572 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
573
GearmanWorker object – InnoDB storage engine
GearmanWorker object, 410_get( ) magic method, 10get method, 134get_class( ) method, 6getDelayedByKey( ) method, 173–174get_fields( ) method, 299getFromCache( ) method, 183getMulti( ) method, 169–170getServers( ) method, 178globals, 357
accessing, 359CodeGen_PECL, defi ning, 318–319critical section, 360defi ning, 358–359thread safety, 359–361True Global Resources, 360
gman_do( ) UDF, 408gman_servers_set( ) UDF, 407–408gman_sum( ) UDF, 408–409GNU General Public License, 133GPL (General Public License), 316GRANT command, 268, 497GROUP BY (MySQL), 30–31GUID (Globally Unique Identifi er), 363
H
Hadoop, 442HANDLER clause, 229–230handlers, 229–230hash tables
accessing, 348, 349looping through, 349modifying, 349
hashing, 505–506hashing functions, 506HashTable data type, 348HAVING clause (MySQL), 32help fi les, generating, 313helper functions, 339–340host permissions, 499HTTP-based user authentication, 460
basic, 460, 461–463digest, 460, 463–466
human readability, 222
I
IGNORE_PATH fl ag, 341IGNORE_URL fl ag, 342
implementation, interfaces, 7implied COMMIT, 250incrementing, memcached, 168–169index workers (Gearman), 434–435indexes
common mistakes, 552–554identifying, 549–550optimizing, 552types, 551
indexingattributes, 376b-tree indexes, 365columns, 376delta indexes, 389–394distributed indexes, 373fi elds, 376FULLTEXT indexes, 365
Boolean mode, 367–368creating, 366issues, 368–369Natural Language mode, 367
inherited, Sphinx, 381merging indexes, 394–395searches, 365–366Sphinx, 372–373
Narada, 416–417TokuDB, 124–125
InfiniDB, 124Infobright, 125INFORMATION_SCHEMA. See I_SINFORMATION_SCHEMA schema, 289–292inheritance, 350–351
classes inheriting interfaces, 7inherited indexes, 381INI directives, 357
CodeGen_PECL, defi ning, 318–319defi ning, 358–359
init( ) function, 285initialization, lazy initialization, 12inner joins (MySQL), 21–23ON, 22syntax, 22–23USING, 22
InnoDB storage engine, 97–98disk space, 99–100MyISAM comparison, 99–102parameters, 98primary key order, 100SQL optimization, 102–103tables, 98–99
563120bindex.indd 573563120bindex.indd 573 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
574
INSERT command – joins
INSERT command, triggers, 233–234INSERT statement, 558
triggers, 233insert worker (Gearman), 429–430INSERT...ON DUPLICATE KEY UPDATE statement,
558–560installation
APC, 132–133eAccelerator, 133–134Gearman, 404–407libmemcached, 155memcached
CentOS, 145–146OpenSolaris, 147from source, 147–148testing, 151–152Ubuntu, 146–147
Memcached Functions for MySQL, 193–196Sphinx, 370–371UDFs, 294–295
checking, 289–292instanceof keyword, 6instances, memcached, 160instantiation, 2–6
interfaces, 7integer values, incrementing/decrementing, 204–206integration points for triggers, 232interface keyword, 7interfaces, 7–8ArrayAccess, 77–78CodeGen_PECL, 321countable, 73–74creating, 354–355defi ning, 7deriving, 7implementing, 7inheritance, 7instantiation, 7Iterator interface, 69–73methods, 70ReadableNode, 7SeekableIterator, 75–76testing variables against, 7
internal maps, 451_invoke( ) magic method, 11I_S
character sets, 486–487collations, 487–488
column privileges, 490–491
extensions, 491metadata, 486MySQL
status variables, 484–485system variables, 485–486
privilege tables, 488profi ling table columns, 483–484schema privileges, 489SHOW command, 478SHOW_PROCESSLIST, 482status tables, 482table objects, 479, 481–482table privileges, 489–490tables, 478, 479–480user privileges, 488
isolation (ACID), 242levels, 247READ_COMMITTED, 244–245READ_UNCOMMITTED, 245–246REPEATABLE_READ, 242–244replication, 247SERIALIZABLE, 246–247
_isset( ) magic method, 10isValidCipher( ) method, 519Iterator interface, 69–73IteratorIterator, 75iterators, 67
actions, 70IteratorIterator, 75methods, 71rewinding, 71
J
job servers, Gearman, 142joins (MySQL), 19–21
aliases, 22case sensitivity, 26–27complex, 27inner joins, 21–23
ON, 22syntax, 22–23USING, 22
left joins, 25multiple tables, 20outer joins, 23–24right joins, 24–25syntax, 25–27
563120bindex.indd 574563120bindex.indd 574 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
575
Kasindorf – maps
K
Kasindorf, Alan, 140key( ) method, 72, 77keywordsabstract, 3clone, 12final, 3instanceof, 6interface, 7parent, 2private, 3protected, 3public, 3WITH ROLLUP, 31–32static, 3, 12
Kickfi re storage engine, 128
L
lambda functions, 65, 78lambda-style functions, 78–81lazy initialization, 12lazy processing, 143left joins (MySQL), 25libgearman, UDFs, 272libmemcached, 153–154
features, 154installation, 155Memcached Functions for MySQL, 193UDFs, 272utility programs, 154
memcat, 155–156memcp, 156memerror, 158memfl ush, 156memrm, 157memslap, 157–158memstat, 157
libmysql, 88LIB_MYSQLUDF_PREG library, 61libraries
interfacing PHP with MySQL, 88LIB_MYSQLUDF_PREG, 61MySQL Stored Routines Library, 231
library dependencies, modules, compiling, 311LICENSE fi le, 316line key, 544_LINE_ magic constant, 8
literal values, 304Livejournal, 402
Gearman and, 401load( ) method, 182loggin, rewrite rules, 450LoggingProxy class, 13–14logic operators (MySQL), 33–34logos, 362–363lookaheads, 52–53lookbehinds, 52–53lookups
random, 451–452text, 451–452
loops, 65–67hash tables, 349iterators, 67
LRU (Least Recently Used) cache, 140lstat( ) function, 290
M
Maesaka, Turo, 140magic constants, 8–9_CLASS_, 8_DIR_, 9_FILE_, 8_Function_, 9_LINE_, 8_METHOD_, 9_NAMESPACE_, 9
magic methods, 8_call( ), 11_callStatic( ), 11classes, 9–11_clone( ), 11_get( ), 10_invoke( ), 11_isset( ), 10_set( ), 10_set_state( ), 11_sleep( ), 9_unset( ), 10_wakeup( ), 9
main directory, 308map/reduce operations, 403maps
internal, 451rewrite maps, 450–455
built-in, 451
563120bindex.indd 575563120bindex.indd 575 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
576
Maria storage engine – Memcached Functions for MySQL
Maria storage engine, 120–121MariaDB, 126MATCH( ) function, 366materialized view, 225mcrypt extension, 503–505mcrypt library, white space, 505md5 hash, decrypting, 459member variables
private, serialization, 10visibilities, 3
memcached, 138–140. See also PECL/memcachedadd method, 163appending, 166–167authorization, 140cache locality, 171–173CAS (check and swap), 174–176class methods, 163–166clients, 153consistent hashing, 140decrementing, 168–169delete( ) method, 168dumb server, 140error handling, 178–179functions, 191–192get method, 164–165getDelayedByKey( ) method, 173–174getMulti( ) method, 169–170getServers( ) method, 178-h switch, 148incrementing, 168–169installation
CentOS, 145–146OpenSolaris, 147from source, 147–148testing, 151–152Ubuntu, 146–147
instances, 140, 160mailing list, 140memcapable key-value stores, 186moxi proxy, 185–186multi-get, 169–170multi-set, 170–171Narada and, 412prepending, 166–167read-through caching, 141replace method, 164replication, 140
serversconnecting to, 197–198connection, 160–161
set method, 164starting, 148–149startup scripts, 149
Debian-based, 150OpenSolaris, 151Redhat-based, 150–151
statistics, 176–178Tokyo Tyrant, 187–188user contract, 140using, 141–144values, storing, 198–199write-back caching, 142write-through caching, 141
Memcached Functions for MySQL, 191–192behavioral functions
memc_behavior_get, 207memc_behavior_set, 207–208memc_list_behaviors, 206–207memc_list_distribution_types, 209memc_list_hash_types, 209
data fetching functions, 204data setting functions
memc_add, 200memc_append, 202–203memc_cas, 201memc_delete, 203memc_prepend, 202memc_replace, 200–201memc_set, 198–199memc_set_by_key, 199–200
incrementing/decrementingmemc_decrement, 205–206memc_increment, 204–205
installationbuilding source, 194confi guring source, 194func table, 196installing UDF, 195
libmemcached, 196–197Perl install utility, 195source distribution directory, 212–214statistical functions, 209–210
memc_stat_get_keys, 211memc_stat_get_value, 211memc_stats, 210–211
563120bindex.indd 576563120bindex.indd 576 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
577
memc_add function – MyISAM storage engine
triggers, 212execution, 214–216
values, 272version functions, 211
memc_libmemcached_version, 212memc_udf_version, 212
memc_add function, 200memc_append function, 202–203memcat, 155–156memc_behavior_get function, 207memc_behavior_set function, 207–208memc_cas function, 201memc_decrement function, 205–206memc_delete function, 203memc_get function, 204memc_increment function, 204–205memc_libmemcached_version function, 212memc_list_behaviors function, 206–207memc_list_distribution_types function, 209memc_list_hash_types function, 209memcp, 156memc_prepend function, 202memc_replace function, 200–201memc_server_count, 198memc_servers_set, 197–198memc_set function, 198–199memc_set_by_key function, 199–200memc_stat_get_keys function, 211memc_stat_get_value function, 211memc_stats function, 210–211memc_udf_version function, 212memerror, 158memfl ush, 156memory management, 328–329Memory storage engine
data persistence, 103parameters, 103table-level locking, 104table size maximum, 104table usage, 103–107
memrm, 157memslap, 157–158memstat, 157Merge storage engine, 110–111merging indexes, 394–395metadata, 477
events, 269–270I_S, 486stored routines, 230–231
_METHOD_ magic constant, 9methods, 351–353
abstract, defi ning, 353calling, 356CodeGen_PECL, defi ning, 320count( ), 73current( ), 72factory methods, 17fetch, 134fetchall_hash_result( ), 299get, 134get_class( ), 6get_fields( ), 299getFromCache( ), 183interface, 70isValidCipher( ), 519iterator methods, 71key( ), 72, 77load( ), 182magic, 8
classes, 9–11next( ), 73print_r( ), 543rewind( ), 71, 76save( ), 182seek( ), 75–76set, 134setMulti( ), 170–171touchPage( ), 77type hinting, 6unlink( ), 78unset( ), 78valid( ), 72var_dump( ), 543visibilities, 3
Microsoft debugger, 273MINIT function, 350, 357moxi (memcached proxy), 185–186MTA (Mail Transfer Agent), 55multiton design patterns, 11–13MultitonExample class, 12–13MVCC (multiversion concurrency control), 242MX (Mail Exchange), 55MyISAM storage engine, 90–91, 93–94
compressed tables, 96high read environment, 97high write environment, 97InnoDB comparison, 99–102Merge storage engine and, 110–111
563120bindex.indd 577563120bindex.indd 577 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
578
MySQL – MySQL
MySQL instance crashes, 97parameters, 94row formats, 94–95version, 96when to use, 97
MySQLbinaries, custom, 89character classes, 60character sets, 486–487
collations, 487–488connecting/disconnecting, 296–297constraints, 35debuggers, 564–565debugging
commands, 564error log, 560–561PROCESSLIST, 562–564slow query log, 561–562
drivers, 88fl ow control, 32, 34–35
CASE function, 34IF( ) function, 34IFNULL( ) function, 35NULLIF( ) function, 35
FULLTEXT indexes, 365HAVING clause, 32joins, 19–21
aliases, 22case sensitivity, 26–27complex, 27inner joins, 21–23left joins, 25multiple tables, 20outer joins, 23–24right joins, 24–25syntax, 25–27
libraries, interfacing with PHP, 88logic operators, 33–34logical operations, 32logical operators
AND, 33NOT, 33OR, 33XOR, 33
Memcached Functions for MySQL (See Memcached Functions for MySQL)
privilege tables, 488
queriesdependent queries, 45GROUP BY, 30–31subqueries, 45–46
regular expressions, 59–62data capture, 61query fi lters, 62replacing strings, 62
relational integrity, 35replication
benefi ts, 264binary log fi le analysis, 256–257breaking, 261–262commands, 261confi guration options, 260issues with, 263–264master analysis, 255–256selective, 262–263slave analysis, 257–258testing, 254–255, 259
security model, 496–497SELECT statements, 28–29server, hardening, 493–501silent column changes, 45status tables, I_S, 482status variables, 484–485storage engines, 87, 89
Archive, 109–110available engines, 89–90Blackhole, 108–109CSV, 112default, 93defi ning, 90–91Falcon, 118–120features, 89Federated, 112–118information, 89–92InnoDB, 97–103Maria, 120–121Memory, 103–107Merge, 110–111MyISAM, 93–97non-transactional, 89–90table, confi rming, 91–92transactional, 89–90
system variables, 485–486tables, derived tables, 46–47
563120bindex.indd 578563120bindex.indd 578 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
579
MySQL Native Driver – parameters
unauthenticated users, 494UNION, 28–29user privileges, 488
MySQL Native Driver (for PHP), 88MySQL Stored Routines Library, 231MySQLi Result objects, 307mysqlnd, 88
as native PHP extension, 88mysql_secure_installation command, 494
N
names, views, 225_NAMESPACE_ magic constant, 9namespaces, 350–351Narada
components, 413–415confi guration fi le, 420–422database tables, 415–416downloading, 413fl ow chart depiction, 439Gearman and, 412
workers, running, 440index page, 435–438memcached and, 412Narada class, 422–429
get( ) method, 425getContent( ) method, 426NaradaWorkerCallback( ) method, 428runWorker( ) method, 428searchIndex( ) method, 427storeContent( ) method, 425verify( ) method, 428
NaradaIndexTimer.php, 438–439open source, 441–442overview, 412running, 439–441Sphinx and, 412
setup, 416–429Sun and, 412
Natural Language mode, 367NDB storage engine, 127networking
clients, building, 344–345servers, building, 345–346
next( ) method, 73NitroEDB storage engine, 127
Node classdefi ning, 3–4polymorphism, 2
nOFB encryption, 504non-blocking sockets, 346non-deterministic cache, 144non-transactional tables, 238–239Norbye, Trond, 140NOT NULL constraint, 35–36NOT operator (MySQL), 33
O
object-oriented PHP, 2–19interfaces, 7–8magic constants, 8–9
objectsCodeGen_PECL, defi ning, 319decorating, 14identifying, 355–356methods, 351–353permissions, 496properties, 353–354table objects, creating, 223–224
observer pattern, 18–19OFB (Output-Feedback Mode) encryption, 504opcode caching, 132open source projects
creating, 281–283Narada, 441–442subdirectories, 282top-level directories, 282–283
open source UDFs, 272OpenSolaris, memcached installation, 147operating system, security, 495optimization, SQL, InnoDB storage engine and,
102–103OR operator (MySQL), 33Our Delta patches, 126outer joins (MySQL), 23–24
P
page caching, 145Pagination class, 75–76parametersCallback, 81
563120bindex.indd 579563120bindex.indd 579 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
580
parent keyword – quote syntax in regular expressions
Memory storage engine, 103MyISAM storage engine, 94stored functions, 226–227stored procedures, 226–227
parent keyword, 2parsing, quoted strings, 80partial page caching, 145passwords
salts, 460SHA-1 hash, 459
PBXT (Primebase Transaction) storage engine, 122–123PEAR packages, 314PECL extensions, 132PECL/Gearman, installation, 404–405PECL/memcached, 158–159
client behavior, 162–163operations, 159–160putting and retrieving data, 163–166
PECL (PHP Extension Community Library), 309Percona builds for storage engine patches, 125Perl, install utility, 195permissions, 495–497
host permissions, 499objects, 496restarting, 498triggers, 237valid, 496views, 223–224
PHPGearman and, 409–412libraries, interfacing with MySQL, 88pure authentication, 466–473
cookies, 471–473sessions, user authentication and, 467–471Sphinx and, 395–399
PHP API functions, consuming, 336–338PHP license, 316PHP_FE, 351phpize program, 312PHP_ME, 351PHP_METHOD, 351php_network.h, 344–345php_printf function, 340, 361php_socket_t, 345php_stream, 341polymorphism, 2–6BlogEntry class, 2ForumTopic class, 2Node class, 2
ports, 537prepending, memcached, 166–167primary keys, InnoDB storage engine, 100printing, extensions, 361print_r( ) method, 543private keyword, 3private member variables, serialization, 10privilege tables (I_S), 488privileges
appropriate use, 499column privileges, 490–491event privileges, 268removing, 497schema privileges, 489stored routines, 230–231table privileges, 489–490user privileges, 488
proactive caching, 145PROCESSLIST, 562–564project directory organization, 281–283properties, 353–354
CodeGen_PECL, defi ning, 320protected keyword, 3protocol wrappers, 522
disabled, 529prototyping, query builder and, 83–85Proven Scaling, 483proxy design pattern, 13–14PSEA (pluggable storage engine architecture), 89InnoDB Plugin, 121–122PBXT, 122–123XtraDB, 123
public keyword, 3publisher/subscriber pattern, 18–19
Q
QEP (Query Execution Plan), 102quantifi ers in regular expressions, 50queries (MySQL)
dependent queries, 45derived tables, 46–47fi ltering, 62GROUP BY, 30–31subqueries
complex, 47–49correlated subqueries, 46
query builder, prototyping, 83–85quote syntax in regular expressions, 51
563120bindex.indd 580563120bindex.indd 580 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
581
quoted strings – rewrite rules
quoted strings, parsing, 80quotes, escaping, 80
R
rainbow tables, 459random lookups, 451–452read operations, Federated storage engine, 112read-through caching, 141, 216–219read-through caching callback, 165ReadableNode interface, 7READ_COMMITTED, 244–245READ_UNCOMMITTED, 245–246records
returning, 72–73seeking specifi c, 75–76validating, 72–73
regular expressions[ ] (square brackets), 50alternation, 51back-references, 53boundary character, 49comments, 49, 54data capture, 53–54exclamation point, 448expert, 52–54general patterns, 49–51MySQL, 59–62Perl-style, 54POSIX-style, 54quantifi ers, 50quote syntax, 51replacing strings, 58–59
relational integrity (MySQL), 35REPEATABLE_READ, 242–244REPLACE command, triggers, 232, 236–237REPLACE statement, 558replacing strings
MySQL, 62regular expressions, 58–59
replay attacks, 507–509replication
benefi ts, 264binary log fi le analysis, 256–257binary logging, 251Blackhole storage engine, 108breaking, 261–262commands, 261confi guration, options, 260
isolation (ACID), 247issues with, 263–264master analysis, 255–256memcached, 140purposes, 250–251selective, 262–263setup
master confi guration, 251–252slave confi guration, 252slave operation, 253
slave analysis, 257–258testing, 254–255, 259
REPORT_ERRORS fl ag, 342REST (Representational State Transfer), 524–531
controller, 525–526cURL, 528–529error codes, 533requests, 529–531resources, 525status codes, 527–528verbs, 524
result set array, returning, 297–300returning records, 72–73REVOKE command, 268, 497rewind( ) method, 71, 76rewinding an iterator, 71rewrite maps, 450–455
built-in, 451rewrite rules
conditional, 447–450exclamation point, 448testing for patterns, 449testing to check fi le or path, 449
directives, 444RewriteCond, 447
fl agschain, 446env, 447forbidden, 445gone, 446last, 446multiple, 447next, 446nocase, 446noescape, 446nosubreq, 446passthrough, 446proxy, 446qsappend, 446
563120bindex.indd 581563120bindex.indd 581 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
582
RewriteCond directive – SOAP
redirect, 445skip, 446type, 446
fl ow, 445–447logging, 450optimization, 450purposes, 443, 444–445random lookups, 451–452structure, 444–445
RewriteCond directive, 447right joins (MySQL), 24–25root user, 494
changing, 498–499routines, 226RPCs (Remote Procedure Calls), 532
S
\s shorthand character, 50Sallings, Dustin, 140save( ) method, 182scaling out, 138schema privileges, 489search engines, Narada, 412–442search worker (Gearman), 433–434searchd (Sphinx), 374–376searchesFULLTEXT indexes, 366indexes, 365–366modifi er values, 366Sphinx, 369, 383
Boolean query syntax, 385extended query syntax, 385–386search modes, 384search utility, 386–388sort modes, 384
securityadditional, 500auditing, 500–501automation attacks, 514–515backdoor, 498bypassing, 498CSRF, 511–514ideal, 499–500introduction, 493operating system, 495permissions, 495–497replay attacks, protecting against, 507–509
SQL injection, protecting against, 506–507XSS (cross-site scripting) attacks, 509–511
seek( ) method, 75–76SeekableIterator interface, 75–76seeking specifi c records, 75–76SELECT statement, 217, 546–555SELECT statements (MySQL), 28–29selective replication, 262–263SERIALIZABLE, 246–247serialization, 9
APC, 135eAccelerator, 135private member variables, 10
serialize( ) function, 9Server SQL, modes, 40–44servers, memcached, connecting to, 197–198session caching, 145_set( ) magic method, 10SET data type, 36–37set method, 134setMulti( ) method, 170–171_set_state( ) magic method, 11setToCache( ) function, 184SHA-1 hash, 459shebang, 518shortened URL applications, 452–455shorthand characters, 50SHOW command, 478, 491–492SHOW MASTER STATUS command, 256SHOW TABLE STATUS command, 92SHOW.ENGINES command, 89–90SHOW_PROCESSLIST, 482shutdown, restricting, 498silent column changes in MySQL, 45single-directional encoding, 505–506singleton design patterns, 11–13SingletonExample class, 11–12SixApart, 402skeleton code
compiling, 309–312creating, 309–312
--skip-grants option, 498_sleep( ) magic method, 9slow query log, 561–562SOAP (Simple Object Access Protocol)
bindings, 537–538client, setup, 540–541library, WSDL, 533–534
563120bindex.indd 582563120bindex.indd 582 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
583
socket pointers – storage engine
requests, envelopes, 532server, setup, 538–540web services, 532–533
socket pointers, valid, 55–56sockets, blocking, 346source distribution directory (Memcached Functions for
MySql), 212–214Sphinx (SQL Phrase Index)
Aksyonoff, Andrew, 369applications using, 395–399data sources, 372, 376–379delta indexes, 391–394distributed indexes, 373indexer, 374indexer options, 382indexes, 372–373
attributes, 376columns, 376defi ning, 379–381fi elds, 376inherited, 381
installation, 370–371Narada and, 412, 416–417PHP and, 395–399programs, 369–370sakila_main data source, 379searchd, 374–376searchd options, 382searches, 383
Boolean query syntax, 385extended query syntax, 385–386modes, 384search utility, 386–388sort modes, 384
Sphinx.conf, 371–382SphinxQL, 388–389starting
running indexer, 382–383searchd, 383
utilities, 369–370sphinx_counter, 390sprintf( ) function, 290SQL injection, protecting against, 506–507sql-mode-traditional-mylsam-sql, 42–43sql-mode-traditional.sql, 42SQL (Structured Query Language)DELETE statement, 556–558EXPLAIN statement, 547–549
indexescommon mistakes, 552–554identifying, 549–550optimizing, 552types, 551
INSERT statement, 558INSERT...ON DUPLICATE KEY UPDATE statement,
558–560optimization, InnoDB storage engine and, 102–103queries, optimizing, 545–558REPLACE statement, 558SELECT statement, 546–555statements
identifying, 545–546reducing, 545UDFs, 300
UPDATE statement, 556sql_mode=NO_ENGINE_SUBSTITUTION, 43–44sql_mode=TRADITIONAL, 43square brackets ([ ]) in regular expressions, 50stack overfl ow errors, 544stack traces
creating, 544–545keys, 544
standalone storage engines, 124–125standard output from functions, 340stat( ) function, 275state caching, 145statement blocks, 228statementsDELETE, 556–558EXPLAIN, 547–549INSERT, 558INSERT...ON DUPLICATE KEY UPDATE, 558–560REPLACE, 558SELECT, 546–555UPDATE, 556
static keyword, 3, 12statistics, memcached, 176–178stepping through code, 302–303storage engineeBay Memory, 127integrity, 44–45Kickfi re, 128MySQL, 87, 89
Archive, 109–110available engines, 89–90Blackhole, 108–109
563120bindex.indd 583563120bindex.indd 583 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
584
stored functions – STREAM_USE_URL fl ag
CSV, 112default, 93defi ning, 90–91Falcon, 118–120features, 89Federated, 112–118information, 89–92InnoDB, 97–103Maria, 120–121Memory, 103–107Merge, 110–111MyISAM, 93–97non-transactional, 89–90table, confi rming, 91–92transactional, 89–90
NDB, 127NitroEDB, 127patch products
Our Delta, 126Percona builds, 125
PSEAInnoDB Plugin, 121–122PBXT, 122–123XtraDB, 123
standalone products, 124Virident, 128
stored functions, 226characteristics, 228parameters, 226–227
stored procedures, 226characteristics, 228parameters, 226–227
stored routinesconditions, 229–230disadvantages, 231extending, 231fl ow control, 230handlers, 229–230logic
cursors, 229variables, 228–229
meta data, 230–231MySQL Stored Routines Library, 231privileges, 230–231
STREAM encryption, 503stream functions, 341–343php_register_url_stream_wrapper, 343php_register_url_stream_wrapper_
volatile, 343php_stream_close, 343
php_stream_context_alloc, 343php_stream_context_del_link, 343php_stream_context_free, 343php_stream_context_get_link, 343php_stream_context_get_option, 343php_stream_context_set, 343php_stream_context_set_link, 343php_stream_context_set_option, 343php_stream_copy_to_mem, 343php_stream_copy_to_stream, 343php_stream_copy_tostream_ex, 343php_stream_eof, 343php_stream_flush, 343php_stream_free, 343php_stream_from_persistent_id, 343php_stream_getc, 343php_stream_get_line, 343php_stream_get_record, 343php_stream_locate_url_wrapper, 343php_stream_mkdir, 343php_stream_opendir, 343php_stream_open_wrapper, 343php_stream_open_wrapper_ex, 343php_stream_putc, 343php_stream_puts, 343php_stream_read, 343php_stream_readdir, 343php_stream_rewind, 343php_stream_rmdir, 343php_stream_scandir, 343php_stream_seek, 343php_stream_set_options, 343php_stream_stat, 343php_stream_tell, 343php_stream_wrapper_log_error, 343php_stream_write, 343php_unregister_url_stream_wrapper, 343php_unregister_url_stream_wrapper_
volatile, 343STREAM_ASSUME_REALPATH fl ag, 342STREAM_DISABLE_OPEN_BASEDIR fl ag, 342STREAM_DISABLE_URL_PROTECTION fl ag, 342STREAM_MUST_SEEK fl ag, 342STREAM_ONLY_GET_HEADERS fl ag, 342STREAM_OPEN_FOR_INCLUDE fl ag, 342STREAM_OPEN_PERSISTENT fl ag, 342streams
fl ags, 341–342validation, 341
STREAM_USE_URL fl ag, 342
563120bindex.indd 584563120bindex.indd 584 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
585
STREAM_WILL_CAST fl ag – UDFs
STREAM_WILL_CAST fl ag, 342strings
converting to, 327–328quoted, parsing, 80replacing
MySQL, 62regular expressions, 58–59
as zvals, 326–328subqueries (MySQL), 45–46
complex, 47–49correlated subqueries, 46derived tables, 46–47
Sun, Narada and, 412syntax
joins, 25–27triggers, 233
T
table-level locking, 104table objects, creating, 223–224table privileges, 489–490table storage engines (MySQL), confi rming, 91–92tables
building, 362non-transactional, 238–239transactional, 239–240
tables InnoDB storage engine, 98–99tables (MySQL)
aliases, 22derived tables, 46–47
terminal types, 6testing
memcached installation, 151–152replication, 254–255, 259unit testing, factory methods, 17variables against interfaces, 7zval, 323–324
tests fi le, 310text lookups, 451–452thread-safe functions, 273thread safety, globals, 359–361TokuDB, 124–125Tokyo Tyrant, 187–188touchPage( ) method, 77tracking, unlinks, 77transactional tables, 239–240
transactions, 237–238isolation level, 242
transparency, Federated storage engine, 113triggers
defi ning, 232DELETE command, 235–236INSERT command, 233–234integration points, 232Memcached Functions for MySQL, 212
execution, 214–216permissions, 237REPLACE command, 236–237syntax, 233UPDATE statement, 234–235
True Global Resources, 360TSRM (Thread Safe Resource Management), 359tsrm_mutex, 360Turck MMCache, 133Turing Test, automation attacks, 514type hinting, 6type key, 544
U
Ubuntu, memcached installation, 146–147UDFs (user defi ned functions), 191, 231, 271
algorithms, 277arguments, 192building, 292–294C-libraries, 272coding, 281debuggers, 273debugging, 300–301
breakpoints, 302–303gdb, 301–302literal values and, 304stepping through code, 302–303
design, high-level, 275–277developing, requirements, 273–274example, 274–275installation, 294–295
checking, 289–292open source, 272
project creation, 281–283overview, 272–273PHP and, 296–300required functions, 274
563120bindex.indd 585563120bindex.indd 585 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
586
unauthenticated users – WSDL
result set array, returning, 297–300running, 295–296source code implementation, 283–289SQL statements, 300thread-safe functions, 273
unauthenticated users, 494UNION (MySQL), 28–29UNIQUE KEY constraint, 37unit testing, factory methods, 17unlink( ) method, 78unlinks, tracking, 77_unset( ) magic method, 10unset( ) method, 78unsetting elements, 77UNSIGNED constraint, 36UPDATE statement, 219–220, 556
triggers, 234–235updating, views, 225URLs
rewrite rules, 444shortened, applications, 452–455
USE_PATH fl ag, 342user authentication
database, 458HTTP-based, 460
basic, 460, 461–463digest, 460, 463–466
need for, 457password, as salted md5 hash, 459pure PHP authentication, 466–473
cookies, 471–473sessions, 467–471
unauthenticated users, 494username, 458–459
user cachingenabling, 133storage, 134
user privileges (I_S), 488users
default, new installation, 494root, 494
changing, 498–499utilities, libmemcached, 154
memcat, 155–156memcp, 156memerror, 158memfl ush, 156memrm, 157
memslap, 157–158memstat, 157
V
valid( ) method, 72valid permissions, 496validation
records, 72–73streams, 341
values, returning, 334–335var_dump( ) method, 543variables, 228–229
classes, 3confi guration, default values, 266extensions, 321–329
zval, 321–328member, serialization, 10testing against interfaces, 7
views, 221–222access permissions, 223–224data warehousing, 225materialized, 225names, 225updating, 225
Virident storage engine, 128visibilities, 3
W
\w shorthand character, 50Waffl egrid, 129_wakeup( ) magic method, 9warnings, 346–347web services, 517
REST (Representational State Transfer), 524–531SOAP, 532–533
WITH ROLLUP keyword, 31–32write-back caching, 142write statements, Federated storage engine, 112write-through caching, 141WSDL (Web Service Descriptor Language), 533–534
defi ning service, 538messages, defi ning, 536ports, 537types, 535–536
complex, 535
563120bindex.indd 586563120bindex.indd 586 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
587
Xing.com – zvals
X
Xing.com, 402XML documents
creating, 314–316extensions as, 314
XOR Cipher, 501–503XOR operator (MySQL), 33XSS (cross-site scripting) attacks, 509–511XtraDB storage engine, 123
Y
Yahoo!, 402
Z
Zend directory, 308Zend engine, 308
memory management, 328–329zend_parase_parameters function, 334ZTS (Zend Thread Safety), 359zval, 321–322
comparing, 324–326reading, 324–326setting, 323–324testing, 323–324
zvals, strings as, 326–328
563120bindex.indd 587563120bindex.indd 587 2/18/10 9:12:27 AM2/18/10 9:12:27 AM
563120bindex.indd 588563120bindex.indd 588 2/18/10 9:12:27 AM2/18/10 9:12:27 AM