![Free-eBooks.net](/resources/img/logo-nfe.png)
![All New Design](/resources/img/allnew.png)
The keen-eyed amongst you will also notice the highlighted lines, we've defined the start and end points for CodeIgniter to pay attention to. The first we've named bm1_start and the second we've named bm1_stop. We can call them anything we like, but that's what I've decided to call them.
We then perform the batch_ insert operation, as shown in the following code snippet: $this->benchmark->mark('bm2_start');
$data = array(
array('firstname' => 'George',
'lastname' => 'Foster'),
array('firstname' => 'Jackie',
'lastname' => 'Foster'),
array('firstname' => 'Antony',
'lastname' => 'Welsh'),
array('firstname' => 'Rowena',
'lastname' => 'Welsh'),
array('firstname' => 'Peter',
'lastname' => 'Foster'),
array('firstname' => 'Jenny',
'lastname' => 'Foster'),
array('firstname' => 'Oliver',
'lastname' => 'Welsh'),
array('firstname' => 'Harrison',
'lastname' => 'Foster'),
array('firstname' => 'Felicity',
'lastname' => 'Foster')
);
$result = $this->bench_model->add_to_db($data);
$this->benchmark->mark('bm2_end');
281
SEO, Caching, and Logging
We're defining a multidimensional array with the details of people we want to add to the database and sending it to the insert_batch() function of bench_model; now the keen eyed among you will again notice the highlighted lines. These are the bm2 start and end points. If the batch_insert() operation returns TRUE (it is inserted into the database correctly), we then call the get_people() model function again, which will return all the records from the database:
if ($result) {
// Who's in the database now?
$this->benchmark->mark('bm3_start');
foreach ($this->bench_model->get_people()->result() as $row) {
echo $row->firstname . ' ' . $row->lastname . '<br />';
}
$this->benchmark->mark('bm3_end');
} else {
echo 'Cannot write to database.';
}
Again, here we define (as highlighted in the previous code) the bm3 start and end points.
That completes our database operations and we move over to reporting of the benchmarks.
We ask CodeIgniter to tell us the execution time between points:
echo '<br /> ---- BENCHMARK POINT STATS ---- <br />';
echo 'BM1 (S) to BM1 (E): ' . $this->benchmark->elapsed_time('bm1_
start','bm1_end') . '<br />';
echo 'BM2 (S) to BM2 (E): ' . $this->benchmark->elapsed_time('bm2_
start','bm2_end') . '<br />';
echo 'BM3 (S) to BM3 (E): ' . $this->benchmark->elapsed_time('bm3_
start','bm3_end') . '<br />';
For each bm1, bm2, and bm3, we want to know the time between the points specified using the $this->benchmark->elapsed_time() function. This function takes two arguments: a start point and an end point. For this recipe, we have asked CodeIgniter to report the time elapsed between each bm# point (where # is the number 1, 2, or 3), but if we wish to we can write this:
echo 'BM1 (S) to BM2 (E): ' . $this->benchmark-
>elapsed_time('bm1_start','bm2_end') . '<br />'
The previous code will report the elapsed time between bm1_start and bm2_end (or from the beginning of the first get_people() query to the end of the batch_insert() query).
Think of each $this->benchmark->mark('bm2_end'); as a checkpoint, and you can use $this->benchmark->elapsed_time('checkpoint_1','checkpoint_2') to return the time elapsed between them.
282
Index
Symbols
$data_to_write variable 116
$db[‘default’][‘cachedir’] option 11
$cap array 262
$db[‘default’][‘cache_on’] option 10
$db[‘default’][‘char_set’] option 11
$config[‘cookie_domain’] = \ 126
$db[‘default’][‘database’],
$config[‘cookie_path’] = \ 127
$config[‘cookie_prefix’] = \ 126
$db[‘default’][‘database’] option 10, 100
$config[‘cookie_secure’] = FALSE; 127
$db[‘default’][‘dbcollat’] option 11
$config[‘csrf_cookie_name’],
$db[‘default’][‘db_debug’] option 10
$db[‘default’][‘dbdriver’] option 10
$config[‘csrf_expire’], config item 106, 171
$db[‘default’][‘dbprefix’] option 10
$config[‘csrf_protection’],
$db[‘default’][‘hostname’],
$config[‘csrf_token_name’],
$db[‘default’][‘hostname’] option 10, 100
$db[‘default’][‘password’],
$config[global_xrsf_filtering’],
config item 106
$db[‘default’][‘password’] option 10, 100
$config[‘sess_cookie_name’],
$db[‘default’][‘pconnect’] option 10
$db[‘default’][‘port’] option 11
$config[‘sess_encrypt_cookie’],
$db[‘default’][‘username’],
$config[‘sess_expiration’],
$db[‘default’][‘username’] option 10, 100
$ config[‘sess_expire_on_close’],
$dob array 205
$end_of_month variable 189
$config[‘sess_match_ip’],
$filename variable 216
$future_descriptions array 209
$config[‘sess_match_useragent’],
$hook array 218
$config[‘sess_table_name’],
$month_as_written array 189
$config[‘sess_use_database’],
$path array 116
$prefs array 200
$data array 39, 86, 98, 190, 216, 262
$start_date variable 189
$start_of_month variable 189
bulk e-mails
$this->benchmark->elapsed_time()
sending, with CodeIgniter Email 76-79
function 282
$this->Cart_model->get_all_products()
C
function 59
$this->db->insert() 140
cache_override 217
$this->db->insert_batch() 140
$this->table->generate() function 86, 90
Cactuslab
$time_in variable 209
ImageMagick, installing on MAC 241, 242
$tpl variable 200
Calendar Library
.htaccess file
appointment manager, building with 190-200
used, for removing index php from
callbacks
address bar 12
/path/to/codeigniter/application/
CAPTCHA
controllers/makepdf.php file 214
/path/to/codeigniter/application/models/
cart
basic cart, ammending 54-58
/path/to/codeigniter/application/views/
items, adding 59
makepdf/view_all_users.php file 214
items, removing 59
A
items, updating 59
Active Record
categories
create (insert) 140
products, adding by 59
delete 148
read (select) 144
categories table 53
update 146
address bar
clear_now() function 220
index.php removing, .htaccess file used 12
allowed_types setting 119
CodeIgniter
alpha 105
alpha_dash 105
alpha_numeric 105
CAPTCHA, form submitting with 257-264
APC (Alternative PHP Caching) 272
cart class 51
application
configuring, for databases 134, 135
appointment manager
building, with Calendar Library 190-200
form elements, sticky 110, 111
attachments
form, submitting with CodeIgniter
sending, with CodeIgniter Email 74-76
B
batch_insert() operation 281, 282
284
current version
images, rotating 247
moving to, current() used 161
images, uploading with 242-244
D
logging errors, style 277
managing, on different environments 7, 8
data
passwords, generating with 31-41
deleting, from database 148-150
passwords, resetting with 43-50
SEO-friendly URLs, using 265-268
inserting, in database 140-143
watermarks, adding with image
selecting, from database 144-146
sending, to multiple views 100-103
watermarks, adding with text 252-254
CodeIgniter Calendar helper
database
building, with database results 183-190
accessing, through library 227-230
CodeIgniter database migrations
CodeIgniter, configuring for 134, 135
CodeIgniter Email
dead sessions, clearing 219-221
attachments, sending with 74-76
bulk e-mails, sending with 76-80
multiple databases, connecting to 135-139
HTML e-mails, sending with 72-74
database query
used, for sending e-mails 70, 71
last database query, finding 156, 157
CodeIgniter Sparks
database result
CodeIgniter Calendar helper,
configuration settings
amending, to run sessions in database 51-53
CSV, generating from 165
controllers
cookie
database settings
acceptance from user, confirming 126-132
managing, on different environments 8-11
count_all_results()
DataTable
returned results number, counting 153, 154
create_batch() public function 143
day_type 187
create() function 143, 193, 200, 201
Create, Read, Update, and Delete (CRUD)
dead sessions
operations 134
clearing, from database 220, 221
cross-site request forgery
decimal 105
delete() function 195
CSRF. See cross-site request forgery
delete_user(), public function 30
CSV
display_override 217
creating, from database result 165, 166
csv_from_result() function 168
DOMPDF Spark
used, for creating PDFs 213-216
285
E
G
e-mails
get_all() function 94
bulk e-mails, sending with
get_main_article() function 102
CodeIgniter Email 76-80
greater_than rule 104
HTML e-mails, sending with
H
sending, with CodeIgniter Email 70, 71
encrypt_name setting 120
hash
errors
comparing 42
displaying, next to form items 112, 113
generating 41
escape_like_str() 177
generating, with $config[‘encryption_key’]
escape_str() 177
generating, without $config[‘encryption_key’]
escaping user input
helper
globally 170
creating, to work with persons date
individually 170
Hooks
cache_override 217
F
creating, in CodeIgniter 216-219
display_override 217
file_name setting 119
post_controller 217
files
post_controller_constructor 217
reading, from file system 113-115
post_system 217
pre_controller 217
uploading, with CodeIgniter 118-122
pre_system 217
writing, to file system 116
HTML e-mails
file system
sending, CodeIgniter Email used 72, 73
HTML table
files, writing to 116
force_download() 166
foreach() loop 151
HTTPS