Improve the shell cgroup feature
[lhc/web/wiklou.git] / includes / job / JobQueueDB.php
1 <?php
2 /**
3 * Database-backed job queue code.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @author Aaron Schulz
22 */
23
24 /**
25 * Class to handle job queues stored in the DB
26 *
27 * @ingroup JobQueue
28 * @since 1.21
29 */
30 class JobQueueDB extends JobQueue {
31 const CACHE_TTL_SHORT = 30; // integer; seconds to cache info without re-validating
32 const CACHE_TTL_LONG = 300; // integer; seconds to cache info that is kept up to date
33 const MAX_AGE_PRUNE = 604800; // integer; seconds a job can live once claimed
34 const MAX_JOB_RANDOM = 2147483647; // integer; 2^31 - 1, used for job_random
35 const MAX_OFFSET = 255; // integer; maximum number of rows to skip
36
37 protected $cluster = false; // string; name of an external DB cluster
38
39 /**
40 * Additional parameters include:
41 * - cluster : The name of an external cluster registered via LBFactory.
42 * If not specified, the primary DB cluster for the wiki will be used.
43 * This can be overridden with a custom cluster so that DB handles will
44 * be retrieved via LBFactory::getExternalLB() and getConnection().
45 * @param $params array
46 */
47 protected function __construct( array $params ) {
48 parent::__construct( $params );
49 $this->cluster = isset( $params['cluster'] ) ? $params['cluster'] : false;
50 }
51
52 /**
53 * @see JobQueue::doIsEmpty()
54 * @return bool
55 */
56 protected function doIsEmpty() {
57 global $wgMemc;
58
59 $key = $this->getCacheKey( 'empty' );
60
61 $isEmpty = $wgMemc->get( $key );
62 if ( $isEmpty === 'true' ) {
63 return true;
64 } elseif ( $isEmpty === 'false' ) {
65 return false;
66 }
67
68 list( $dbr, $scope ) = $this->getSlaveDB();
69 $found = $dbr->selectField( // unclaimed job
70 'job', '1', array( 'job_cmd' => $this->type, 'job_token' => '' ), __METHOD__
71 );
72 $wgMemc->add( $key, $found ? 'false' : 'true', self::CACHE_TTL_LONG );
73
74 return !$found;
75 }
76
77 /**
78 * @see JobQueue::doGetSize()
79 * @return integer
80 */
81 protected function doGetSize() {
82 global $wgMemc;
83
84 $key = $this->getCacheKey( 'size' );
85
86 $size = $wgMemc->get( $key );
87 if ( is_int( $size ) ) {
88 return $size;
89 }
90
91 list( $dbr, $scope ) = $this->getSlaveDB();
92 $size = (int)$dbr->selectField( 'job', 'COUNT(*)',
93 array( 'job_cmd' => $this->type, 'job_token' => '' ),
94 __METHOD__
95 );
96 $wgMemc->set( $key, $size, self::CACHE_TTL_SHORT );
97
98 return $size;
99 }
100
101 /**
102 * @see JobQueue::doGetAcquiredCount()
103 * @return integer
104 */
105 protected function doGetAcquiredCount() {
106 global $wgMemc;
107
108 $key = $this->getCacheKey( 'acquiredcount' );
109
110 $count = $wgMemc->get( $key );
111 if ( is_int( $count ) ) {
112 return $count;
113 }
114
115 list( $dbr, $scope ) = $this->getSlaveDB();
116 $count = (int)$dbr->selectField( 'job', 'COUNT(*)',
117 array( 'job_cmd' => $this->type, "job_token != {$dbr->addQuotes( '' )}" ),
118 __METHOD__
119 );
120 $wgMemc->set( $key, $count, self::CACHE_TTL_SHORT );
121
122 return $count;
123 }
124
125 /**
126 * @see JobQueue::doBatchPush()
127 * @param array $jobs
128 * @param $flags
129 * @throws DBError|Exception
130 * @return bool
131 */
132 protected function doBatchPush( array $jobs, $flags ) {
133 if ( count( $jobs ) ) {
134 list( $dbw, $scope ) = $this->getMasterDB();
135
136 $rowSet = array(); // (sha1 => job) map for jobs that are de-duplicated
137 $rowList = array(); // list of jobs for jobs that are are not de-duplicated
138
139 foreach ( $jobs as $job ) {
140 $row = $this->insertFields( $job );
141 if ( $job->ignoreDuplicates() ) {
142 $rowSet[$row['job_sha1']] = $row;
143 } else {
144 $rowList[] = $row;
145 }
146 }
147
148 $atomic = ( $flags & self::QoS_Atomic );
149 $key = $this->getCacheKey( 'empty' );
150 $ttl = self::CACHE_TTL_LONG;
151
152 $dbw->onTransactionIdle(
153 function() use ( $dbw, $rowSet, $rowList, $atomic, $key, $ttl, $scope
154 ) {
155 global $wgMemc;
156
157 if ( $atomic ) {
158 $dbw->begin( __METHOD__ ); // wrap all the job additions in one transaction
159 }
160 try {
161 // Strip out any duplicate jobs that are already in the queue...
162 if ( count( $rowSet ) ) {
163 $res = $dbw->select( 'job', 'job_sha1',
164 array(
165 // No job_type condition since it's part of the job_sha1 hash
166 'job_sha1' => array_keys( $rowSet ),
167 'job_token' => '' // unclaimed
168 ),
169 __METHOD__
170 );
171 foreach ( $res as $row ) {
172 wfDebug( "Job with hash '{$row->job_sha1}' is a duplicate." );
173 unset( $rowSet[$row->job_sha1] ); // already enqueued
174 }
175 }
176 // Build the full list of job rows to insert
177 $rows = array_merge( $rowList, array_values( $rowSet ) );
178 // Insert the job rows in chunks to avoid slave lag...
179 foreach ( array_chunk( $rows, 50 ) as $rowBatch ) {
180 $dbw->insert( 'job', $rowBatch, __METHOD__ );
181 }
182 wfIncrStats( 'job-insert', count( $rows ) );
183 wfIncrStats( 'job-insert-duplicate',
184 count( $rowSet ) + count( $rowList ) - count( $rows ) );
185 } catch ( DBError $e ) {
186 if ( $atomic ) {
187 $dbw->rollback( __METHOD__ );
188 }
189 throw $e;
190 }
191 if ( $atomic ) {
192 $dbw->commit( __METHOD__ );
193 }
194
195 $wgMemc->set( $key, 'false', $ttl ); // queue is not empty
196 } );
197 }
198
199 return true;
200 }
201
202 /**
203 * @see JobQueue::doPop()
204 * @return Job|bool
205 */
206 protected function doPop() {
207 global $wgMemc;
208
209 if ( $wgMemc->get( $this->getCacheKey( 'empty' ) ) === 'true' ) {
210 return false; // queue is empty
211 }
212
213 list( $dbw, $scope ) = $this->getMasterDB();
214 $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction
215
216 $uuid = wfRandomString( 32 ); // pop attempt
217 $job = false; // job popped off
218 // Occasionally recycle jobs back into the queue that have been claimed too long
219 if ( mt_rand( 0, 99 ) == 0 ) {
220 $this->recycleStaleJobs();
221 }
222 do { // retry when our row is invalid or deleted as a duplicate
223 // Try to reserve a row in the DB...
224 if ( in_array( $this->order, array( 'fifo', 'timestamp' ) ) ) {
225 $row = $this->claimOldest( $uuid );
226 } else { // random first
227 $rand = mt_rand( 0, self::MAX_JOB_RANDOM ); // encourage concurrent UPDATEs
228 $gte = (bool)mt_rand( 0, 1 ); // find rows with rand before/after $rand
229 $row = $this->claimRandom( $uuid, $rand, $gte );
230 }
231 // Check if we found a row to reserve...
232 if ( !$row ) {
233 $wgMemc->set( $this->getCacheKey( 'empty' ), 'true', self::CACHE_TTL_LONG );
234 break; // nothing to do
235 }
236 wfIncrStats( 'job-pop' );
237 // Get the job object from the row...
238 $title = Title::makeTitleSafe( $row->job_namespace, $row->job_title );
239 if ( !$title ) {
240 $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ );
241 wfDebugLog( 'JobQueueDB', "Row has invalid title '{$row->job_title}'." );
242 continue; // try again
243 }
244 $job = Job::factory( $row->job_cmd, $title,
245 self::extractBlob( $row->job_params ), $row->job_id );
246 $job->id = $row->job_id; // XXX: work around broken subclasses
247 // Flag this job as an old duplicate based on its "root" job...
248 if ( $this->isRootJobOldDuplicate( $job ) ) {
249 wfIncrStats( 'job-pop-duplicate' );
250 $job = DuplicateJob::newFromJob( $job ); // convert to a no-op
251 }
252 break; // done
253 } while( true );
254
255 return $job;
256 }
257
258 /**
259 * Reserve a row with a single UPDATE without holding row locks over RTTs...
260 *
261 * @param $uuid string 32 char hex string
262 * @param $rand integer Random unsigned integer (31 bits)
263 * @param $gte bool Search for job_random >= $random (otherwise job_random <= $random)
264 * @return Row|false
265 */
266 protected function claimRandom( $uuid, $rand, $gte ) {
267 global $wgMemc;
268
269 list( $dbw, $scope ) = $this->getMasterDB();
270 // Check cache to see if the queue has <= OFFSET items
271 $tinyQueue = $wgMemc->get( $this->getCacheKey( 'small' ) );
272
273 $row = false; // the row acquired
274 $invertedDirection = false; // whether one job_random direction was already scanned
275 // This uses a replication safe method for acquiring jobs. One could use UPDATE+LIMIT
276 // instead, but that either uses ORDER BY (in which case it deadlocks in MySQL) or is
277 // not replication safe. Due to http://bugs.mysql.com/bug.php?id=6980, subqueries cannot
278 // be used here with MySQL.
279 do {
280 if ( $tinyQueue ) { // queue has <= MAX_OFFSET rows
281 // For small queues, using OFFSET will overshoot and return no rows more often.
282 // Instead, this uses job_random to pick a row (possibly checking both directions).
283 $ineq = $gte ? '>=' : '<=';
284 $dir = $gte ? 'ASC' : 'DESC';
285 $row = $dbw->selectRow( 'job', '*', // find a random job
286 array(
287 'job_cmd' => $this->type,
288 'job_token' => '', // unclaimed
289 "job_random {$ineq} {$dbw->addQuotes( $rand )}" ),
290 __METHOD__,
291 array( 'ORDER BY' => "job_random {$dir}" )
292 );
293 if ( !$row && !$invertedDirection ) {
294 $gte = !$gte;
295 $invertedDirection = true;
296 continue; // try the other direction
297 }
298 } else { // table *may* have >= MAX_OFFSET rows
299 // Bug 42614: "ORDER BY job_random" with a job_random inequality causes high CPU
300 // in MySQL if there are many rows for some reason. This uses a small OFFSET
301 // instead of job_random for reducing excess claim retries.
302 $row = $dbw->selectRow( 'job', '*', // find a random job
303 array(
304 'job_cmd' => $this->type,
305 'job_token' => '', // unclaimed
306 ),
307 __METHOD__,
308 array( 'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) )
309 );
310 if ( !$row ) {
311 $tinyQueue = true; // we know the queue must have <= MAX_OFFSET rows
312 $wgMemc->set( $this->getCacheKey( 'small' ), 1, 30 );
313 continue; // use job_random
314 }
315 }
316 if ( $row ) { // claim the job
317 $dbw->update( 'job', // update by PK
318 array(
319 'job_token' => $uuid,
320 'job_token_timestamp' => $dbw->timestamp(),
321 'job_attempts = job_attempts+1' ),
322 array( 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' ),
323 __METHOD__
324 );
325 // This might get raced out by another runner when claiming the previously
326 // selected row. The use of job_random should minimize this problem, however.
327 if ( !$dbw->affectedRows() ) {
328 $row = false; // raced out
329 }
330 } else {
331 break; // nothing to do
332 }
333 } while ( !$row );
334
335 return $row;
336 }
337
338 /**
339 * Reserve a row with a single UPDATE without holding row locks over RTTs...
340 *
341 * @param $uuid string 32 char hex string
342 * @return Row|false
343 */
344 protected function claimOldest( $uuid ) {
345 list( $dbw, $scope ) = $this->getMasterDB();
346
347 $row = false; // the row acquired
348 do {
349 if ( $dbw->getType() === 'mysql' ) {
350 // Per http://bugs.mysql.com/bug.php?id=6980, we can't use subqueries on the
351 // same table being changed in an UPDATE query in MySQL (gives Error: 1093).
352 // Oracle and Postgre have no such limitation. However, MySQL offers an
353 // alternative here by supporting ORDER BY + LIMIT for UPDATE queries.
354 $dbw->query( "UPDATE {$dbw->tableName( 'job' )} " .
355 "SET " .
356 "job_token = {$dbw->addQuotes( $uuid ) }, " .
357 "job_token_timestamp = {$dbw->addQuotes( $dbw->timestamp() )}, " .
358 "job_attempts = job_attempts+1 " .
359 "WHERE ( " .
360 "job_cmd = {$dbw->addQuotes( $this->type )} " .
361 "AND job_token = {$dbw->addQuotes( '' )} " .
362 ") ORDER BY job_id ASC LIMIT 1",
363 __METHOD__
364 );
365 } else {
366 // Use a subquery to find the job, within an UPDATE to claim it.
367 // This uses as much of the DB wrapper functions as possible.
368 $dbw->update( 'job',
369 array(
370 'job_token' => $uuid,
371 'job_token_timestamp' => $dbw->timestamp(),
372 'job_attempts = job_attempts+1' ),
373 array( 'job_id = (' .
374 $dbw->selectSQLText( 'job', 'job_id',
375 array( 'job_cmd' => $this->type, 'job_token' => '' ),
376 __METHOD__,
377 array( 'ORDER BY' => 'job_id ASC', 'LIMIT' => 1 ) ) .
378 ')'
379 ),
380 __METHOD__
381 );
382 }
383 // Fetch any row that we just reserved...
384 if ( $dbw->affectedRows() ) {
385 $row = $dbw->selectRow( 'job', '*',
386 array( 'job_cmd' => $this->type, 'job_token' => $uuid ), __METHOD__
387 );
388 if ( !$row ) { // raced out by duplicate job removal
389 wfDebugLog( 'JobQueueDB', "Row deleted as duplicate by another process." );
390 }
391 } else {
392 break; // nothing to do
393 }
394 } while ( !$row );
395
396 return $row;
397 }
398
399 /**
400 * Recycle or destroy any jobs that have been claimed for too long
401 *
402 * @return integer Number of jobs recycled/deleted
403 */
404 protected function recycleStaleJobs() {
405 $now = time();
406 list( $dbw, $scope ) = $this->getMasterDB();
407 $count = 0; // affected rows
408
409 if ( !$dbw->lock( "jobqueue-recycle-{$this->type}", __METHOD__, 1 ) ) {
410 return $count; // already in progress
411 }
412
413 // Remove claims on jobs acquired for too long if enabled...
414 if ( $this->claimTTL > 0 ) {
415 $claimCutoff = $dbw->timestamp( $now - $this->claimTTL );
416 // Get the IDs of jobs that have be claimed but not finished after too long.
417 // These jobs can be recycled into the queue by expiring the claim. Selecting
418 // the IDs first means that the UPDATE can be done by primary key (less deadlocks).
419 $res = $dbw->select( 'job', 'job_id',
420 array(
421 'job_cmd' => $this->type,
422 "job_token != {$dbw->addQuotes( '' )}", // was acquired
423 "job_token_timestamp < {$dbw->addQuotes( $claimCutoff )}", // stale
424 "job_attempts < {$dbw->addQuotes( self::MAX_ATTEMPTS )}" ), // retries left
425 __METHOD__
426 );
427 $ids = array_map( function( $o ) { return $o->job_id; }, iterator_to_array( $res ) );
428 if ( count( $ids ) ) {
429 // Reset job_token for these jobs so that other runners will pick them up.
430 // Set the timestamp to the current time, as it is useful to now that the job
431 // was already tried before (the timestamp becomes the "released" time).
432 $dbw->update( 'job',
433 array(
434 'job_token' => '',
435 'job_token_timestamp' => $dbw->timestamp( $now ) ), // time of release
436 array(
437 'job_id' => $ids ),
438 __METHOD__
439 );
440 $count += $dbw->affectedRows();
441 wfIncrStats( 'job-recycle', $dbw->affectedRows() );
442 }
443 }
444
445 // Just destroy any stale jobs...
446 $pruneCutoff = $dbw->timestamp( $now - self::MAX_AGE_PRUNE );
447 $conds = array(
448 'job_cmd' => $this->type,
449 "job_token != {$dbw->addQuotes( '' )}", // was acquired
450 "job_token_timestamp < {$dbw->addQuotes( $pruneCutoff )}" // stale
451 );
452 if ( $this->claimTTL > 0 ) { // only prune jobs attempted too many times...
453 $conds[] = "job_attempts >= {$dbw->addQuotes( self::MAX_ATTEMPTS )}";
454 }
455 // Get the IDs of jobs that are considered stale and should be removed. Selecting
456 // the IDs first means that the UPDATE can be done by primary key (less deadlocks).
457 $res = $dbw->select( 'job', 'job_id', $conds, __METHOD__ );
458 $ids = array_map( function( $o ) { return $o->job_id; }, iterator_to_array( $res ) );
459 if ( count( $ids ) ) {
460 $dbw->delete( 'job', array( 'job_id' => $ids ), __METHOD__ );
461 $count += $dbw->affectedRows();
462 }
463
464 $dbw->unlock( "jobqueue-recycle-{$this->type}", __METHOD__ );
465
466 return $count;
467 }
468
469 /**
470 * @see JobQueue::doAck()
471 * @param Job $job
472 * @throws MWException
473 * @return Job|bool
474 */
475 protected function doAck( Job $job ) {
476 if ( !$job->getId() ) {
477 throw new MWException( "Job of type '{$job->getType()}' has no ID." );
478 }
479
480 list( $dbw, $scope ) = $this->getMasterDB();
481 $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction
482
483 // Delete a row with a single DELETE without holding row locks over RTTs...
484 $dbw->delete( 'job',
485 array( 'job_cmd' => $this->type, 'job_id' => $job->getId() ), __METHOD__ );
486
487 return true;
488 }
489
490 /**
491 * @see JobQueue::doDeduplicateRootJob()
492 * @param Job $job
493 * @throws MWException
494 * @return bool
495 */
496 protected function doDeduplicateRootJob( Job $job ) {
497 $params = $job->getParams();
498 if ( !isset( $params['rootJobSignature'] ) ) {
499 throw new MWException( "Cannot register root job; missing 'rootJobSignature'." );
500 } elseif ( !isset( $params['rootJobTimestamp'] ) ) {
501 throw new MWException( "Cannot register root job; missing 'rootJobTimestamp'." );
502 }
503 $key = $this->getRootJobCacheKey( $params['rootJobSignature'] );
504 // Callers should call batchInsert() and then this function so that if the insert
505 // fails, the de-duplication registration will be aborted. Since the insert is
506 // deferred till "transaction idle", do the same here, so that the ordering is
507 // maintained. Having only the de-duplication registration succeed would cause
508 // jobs to become no-ops without any actual jobs that made them redundant.
509 list( $dbw, $scope ) = $this->getMasterDB();
510 $dbw->onTransactionIdle( function() use ( $params, $key, $scope ) {
511 global $wgMemc;
512
513 $timestamp = $wgMemc->get( $key ); // current last timestamp of this job
514 if ( $timestamp && $timestamp >= $params['rootJobTimestamp'] ) {
515 return true; // a newer version of this root job was enqueued
516 }
517
518 // Update the timestamp of the last root job started at the location...
519 return $wgMemc->set( $key, $params['rootJobTimestamp'], 14*86400 ); // 2 weeks
520 } );
521
522 return true;
523 }
524
525 /**
526 * Check if the "root" job of a given job has been superseded by a newer one
527 *
528 * @param $job Job
529 * @return bool
530 */
531 protected function isRootJobOldDuplicate( Job $job ) {
532 global $wgMemc;
533
534 $params = $job->getParams();
535 if ( !isset( $params['rootJobSignature'] ) ) {
536 return false; // job has no de-deplication info
537 } elseif ( !isset( $params['rootJobTimestamp'] ) ) {
538 trigger_error( "Cannot check root job; missing 'rootJobTimestamp'." );
539 return false;
540 }
541
542 // Get the last time this root job was enqueued
543 $timestamp = $wgMemc->get( $this->getRootJobCacheKey( $params['rootJobSignature'] ) );
544
545 // Check if a new root job was started at the location after this one's...
546 return ( $timestamp && $timestamp > $params['rootJobTimestamp'] );
547 }
548
549 /**
550 * @see JobQueue::doWaitForBackups()
551 * @return void
552 */
553 protected function doWaitForBackups() {
554 wfWaitForSlaves();
555 }
556
557 /**
558 * @return Array (DatabaseBase, ScopedCallback)
559 */
560 protected function getSlaveDB() {
561 return $this->getDB( DB_SLAVE );
562 }
563
564 /**
565 * @return Array (DatabaseBase, ScopedCallback)
566 */
567 protected function getMasterDB() {
568 return $this->getDB( DB_MASTER );
569 }
570
571 /**
572 * @param $index integer (DB_SLAVE/DB_MASTER)
573 * @return Array (DatabaseBase, ScopedCallback)
574 */
575 protected function getDB( $index ) {
576 $lb = ( $this->cluster !== false )
577 ? wfGetLBFactory()->getExternalLB( $this->cluster, $this->wiki )
578 : wfGetLB( $this->wiki );
579 $conn = $lb->getConnection( $index, array(), $this->wiki );
580 return array(
581 $conn,
582 new ScopedCallback( function() use ( $lb, $conn ) {
583 $lb->reuseConnection( $conn );
584 } )
585 );
586 }
587
588 /**
589 * @param $job Job
590 * @return array
591 */
592 protected function insertFields( Job $job ) {
593 list( $dbw, $scope ) = $this->getMasterDB();
594 return array(
595 // Fields that describe the nature of the job
596 'job_cmd' => $job->getType(),
597 'job_namespace' => $job->getTitle()->getNamespace(),
598 'job_title' => $job->getTitle()->getDBkey(),
599 'job_params' => self::makeBlob( $job->getParams() ),
600 // Additional job metadata
601 'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ),
602 'job_timestamp' => $dbw->timestamp(),
603 'job_sha1' => wfBaseConvert(
604 sha1( serialize( $job->getDeduplicationInfo() ) ),
605 16, 36, 31
606 ),
607 'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
608 );
609 }
610
611 /**
612 * @return string
613 */
614 private function getCacheKey( $property ) {
615 list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
616 return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, $property );
617 }
618
619 /**
620 * @param string $signature Hash identifier of the root job
621 * @return string
622 */
623 private function getRootJobCacheKey( $signature ) {
624 list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
625 return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, 'rootjob', $signature );
626 }
627
628 /**
629 * @param $params
630 * @return string
631 */
632 protected static function makeBlob( $params ) {
633 if ( $params !== false ) {
634 return serialize( $params );
635 } else {
636 return '';
637 }
638 }
639
640 /**
641 * @param $blob
642 * @return bool|mixed
643 */
644 protected static function extractBlob( $blob ) {
645 if ( (string)$blob !== '' ) {
646 return unserialize( $blob );
647 } else {
648 return false;
649 }
650 }
651 }