Skip to content

Speed up your page

Daniel Neto edited this page Aug 24, 2021 · 34 revisions

I will try to explain here the magic we use to try to make our pages load faster and handle thousands of requests.

Enabling these options will certainly make your site load faster, but the content presented may not be the most recent.

for example, you just upload a video, and you can already see the video in the video manager, but it still does not appear on the main page. Do not worry, YouPHPTube is on the back updating it and will display for you soon, we will prioritize the quick presentation, even if this is not the latest content.

Enable Cache Plugin

Websites are generally viewed hundreds, thousands, or sometimes even millions of times per month. Normally, each time a browser requests a web page, the server has to do a bunch of complex (and time-consuming) calculations. But if you enable this plugin instead process every request you will serve static pages that expire in a specific amount of time, and then this page will be recreated.

Enable a CDN

The purpose of this is to minimize the distance between your visitors and your video files, a CDN stores a cached version of your content in multiple geographic locations.

To use a CDN please read this

https://github.com/WWBN/AVideo/wiki/CDN-Plugin

Disable media access Security

We use the apache xsend file to control every file access on our site, but for that, we have to check every time if your user has the proper right to access it. To avoid PHP to be querying on each file access (JS, CSS, Images, and videos) Disable the xsendfile.

To do this edit your .htaccess file and comment RewriteRule regarding xsendfile, so after the comment, you should have a configuration just like below

# It must be before image not found
<IfModule mod_xsendfile.c>
   #RewriteRule    ^videos/([A-Za-z0-9-_.]+)$ view/xsendfile.php?file=$1    [QSA]
</IfModule>  

But be aware, if you disable the xsendfile your plugin SecureVideosDirectory will be useless.

Tuning Your Apache Server

Apache2Buddy

The Apache2Buddy script, similar to MySQLTuner, reviews your Apache setup and makes suggestions based on your Apache process memory and overall RAM. Although it is a fairly basic program, that focuses on the MaxClients directive, Apache2Buddy is useful. You can run the script with the following command:

curl -sL https://raw.githubusercontent.com/richardforth/apache2buddy/master/apache2buddy.pl | sudo perl

and edit this file to follow the apache2buddy recommendations

nano /etc/apache2/mods-enabled/mpm_prefork.conf

Here is a sample configuration the apache2buddy will let you know the MaxRequestWorkers value

<IfModule mpm_prefork_module>
    ServerLimit             5000
    StartServers            5
    MinSpareServers         5
    MaxSpareServers         10
    MaxRequestWorkers       1500
    MaxConnectionsPerChild  0
</IfModule>

More Details

MySQLTuner script.

The MySQLTuner is a script written in Perl and allows you to quickly test your MySQL configuration and it gives you suggestions for adjustments to increase performance and stability.

According to the official GitHub page, it supports 300 indicators for MySQL/MariaDB/Percona Server in this last version.

To run the script you could do the following:

SSH to your server and run

curl -sL http://mysqltuner.pl/ | sudo perl

The script would run multiple checks against your MySQL instance

change the Variables to adjust, usually, you can add/change the variables on this file

nano /etc/mysql/mysql.conf.d/mysqld.cnf

YPTSocket

If you will have over 1k users at the same time you may need to follow this http://socketo.me/docs/deploy#ulimit

Those are the commands that work for me

export PKG_CONFIG_PATH=/usr/lib/pkgconfig
sudo apt-get install libevent-dev php-pear php-dev make pkg-config

Edit php.ini nano /etc/php/7.4/apache2/php.ini and add extension=event.so

Clone this wiki locally