Weitere ähnliche Inhalte Ähnlich wie Memory Management in WordPress (20) Mehr von Konstantin Kovshenin (8) Kürzlich hochgeladen (20) Memory Management in WordPress19. ... tried to allocate 8552 bytes in
/path/to/wp-includes/wp-db.php
on line 1775
20. ... tried to allocate 8552 bytes in
/path/to/wp-includes/wp-db.php
on line 1775
1775: while ( $row = mysqli_fetch_object( ...
21. ... tried to allocate 8552 bytes in
/path/to/wp-includes/wp-db.php
on line 1775
1775: while ( $row = mysqli_fetch_object( ...
35. ... tried to allocate 8552 bytes in
/path/to/wp-includes/wp-db.php
on line 1775
37. Call Stack:
34032184 6. do_action()
.../htdocs/wp-settings.php:393
34925000 7. call_user_func_array:{}()
.../wp-includes/plugin.php:525
34925104 8. my_plugin_init()
.../wp-includes/plugin.php:525
134139664 9. wpdb->query()
.../wp-content/plugins/memory.php:25
134172496 10. mysqli_fetch_object()
.../wp-includes/wp-db.php:1775
42. // Pretty bad
$posts = get_posts( array(
'posts_per_page' => -1,
// ...
) );
foreach ( $posts as $post ) {
// ...
}
43. // A little better
$paged = 1;
while ( $posts = get_posts( array(
'posts_per_page' => 100,
'paged' => $paged++,
) ) ) {
foreach ( $posts as $post ) {
// ...
}
}
44. // Good
wp_suspend_cache_addition( true );
$paged = 1;
while ( $posts = get_posts( array(
'posts_per_page' => 100,
'paged' => $paged++,
) ) ) {
// foreach ...
}
wp_suspend_cache_addition( false );
48. // Not so good
ob_start( 'ob_callback' );
// Much better
ob_start( 'ob_callback', 1024*1024*2 );
function ob_callback( $content, $phase ) {
// ...
}
52. add_action( 'shutdown', function() {
$line = json_encode( array(
'timestamp' => time(),
'request_uri' => $_SERVER['REQUEST_URI'],
'peak_memory' => memory_get_peak_usage(),
) );
file_put_contents( '/tmp/php-memory.log',
$line . PHP_EOL, FILE_APPEND | LOCK_EX );
});
59. Attributions:
Success Kid (Sammy Griner): https://en.wikipedia.org/wiki/Success_Kid
Ninja character: http://www.vecteezy.com/vector-art/88129-ninja-vector-set
Blood spatter CC-Attr-ShareALike 4.0: http://www.freevector.com/splattered-blood-graphics-set
User icons by FontAwesome, SIL OFL 1.1: http://fontawesome.io