R
R
Ruslan Makarov2015-10-04 00:46:21
PHP
Ruslan Makarov, 2015-10-04 00:46:21

If there is, then show me - in Wordpress, is it harmful?

Good evening!
Please tell me, I use the "If there is, then show" condition on the WordPress pages to display additional fields specified in the post. I.e:

<?php if ( get_post_meta($post->ID, 'имя-поля', true) ) : ?>
Ляля <?php echo get_post_meta($post->ID, 'имя-поля', true) ?> - <?php the_title(); ?> лялял <?php the_title();>
<?php endif; ?>

And the fact is that on each page I use this condition more than 15 times ...
The number of page views per month is about 700k + -100k ( 16-27k per day ).
What is the question: Is the server heavily "loading" this condition?
Reason for the question: Periodically, the base of the entire server began to fall, only a reboot helps.
VPS: - CPU2 x 2 GHz, RAM 4 GB, Debian 7, Apache, MySQL
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Ruslan Makarov, 2015-10-07
@facepook

Thanks everyone for the replies.
I solved the problem by changing the hoster + slightly improved the hardware.
Now: VDS - 8 GB RAM, 6 CPU cores
Problems are gone!
PS: The last straw was the inaccessibility of the site for 7 hours due to a complete server crash (not only the database, as it was before)

I
Igor Vorotnev, 2015-10-04
@HeadOnFire

Do you have Memcached / Redis on the server? In general, when you receive a post/posts, by default WP requests and caches their metadata. So all calls to get_post_meta() inside the Loop do not give any load on the database, these requests go exclusively to the cache (runtime or persistent). So you can safely use such code and not worry about it.
As for MySQL itself - keep it running for at least a week (optimally - a month) in order to accumulate statistics. Analyze - via MySQL Tuner, PHPMyAdmin, via SQLProfiler, mysqlslap, see slow query log, look for memory leaks or sticky queries.

D
Dmitry Korolev, 2015-10-04
@Apathetic

if ( $var = get_post_meta($post->ID, 'имя-поля', true) )

and then work with this $var.
But the database does not fall because of this, since requests are cached, and there is no particular load.

D
Dmitry, 2015-10-04
@dimasmagadan

this will not give a large load, as mentioned above, requests are cached.
but, if you are very worried, you can collect all custom fields once with one request into one variable
and continue to use it in your code on this page like this

<?php if ( isset($custom['имя-поля']) && !empty($custom['имя-поля'][0])) : ?>
Ляля <?php echo $custom['имя-поля'][0]; ?> - <?php the_title(); ?> лялял <?php the_title();>
<?php endif; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question