<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>php - Grohs Fabian</title>
	<atom:link href="https://grohsfabian.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>https://grohsfabian.com/tag/php/</link>
	<description>Yet another web developer with a blog 🤷‍♂️.</description>
	<lastBuildDate>Fri, 04 Nov 2022 21:24:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://grohsfabian.com/wp-content/uploads/2020/03/6iK6Agse_400x400-150x150.jpg</url>
	<title>php - Grohs Fabian</title>
	<link>https://grohsfabian.com/tag/php/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Fixing XSS Through SVG File Uploads PHP</title>
		<link>https://grohsfabian.com/xss-through-svg-file-uploads-how-to-fix-with-php/</link>
					<comments>https://grohsfabian.com/xss-through-svg-file-uploads-how-to-fix-with-php/#respond</comments>
		
		<dc:creator><![CDATA[grohsfabian]]></dc:creator>
		<pubDate>Fri, 04 Nov 2022 21:23:59 +0000</pubDate>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[svg]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[xss]]></category>
		<guid isPermaLink="false">https://grohsfabian.com/?p=423</guid>

					<description><![CDATA[<p>Using Javascript code inside of an SVG file and then uploading it to a website that accepts SVG files &#38; does not sanitize their content. This is how a ton of websites fail and are directly exposed to this XSS vulnerability. You have two choices: How is this exploit working? Any type of JS code ... <a title="Fixing XSS Through SVG File Uploads PHP" class="read-more" href="https://grohsfabian.com/xss-through-svg-file-uploads-how-to-fix-with-php/" aria-label="Read more about Fixing XSS Through SVG File Uploads PHP">Read more</a></p>
<p>The post <a href="https://grohsfabian.com/xss-through-svg-file-uploads-how-to-fix-with-php/">Fixing XSS Through SVG File Uploads PHP</a> appeared first on <a href="https://grohsfabian.com">Grohs Fabian</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Using Javascript code inside of an SVG file and then uploading it to a website that accepts SVG files &amp; does not sanitize their content.</p>



<p>This is how a ton of websites fail and are directly exposed to this XSS vulnerability.</p>



<p>You have two choices:</p>



<ul class="wp-block-list">
<li>Do not allow users to upload SVG files</li>



<li>Allow users to upload SVG files, but use an SVG cleaner on upload</li>
</ul>



<span id="more-423"></span>



<h2 class="wp-block-heading">How is this exploit working?</h2>



<p>Any type of JS code can be added inside an SVG file.</p>



<p>You upload the SVG image file to a website that allows SVG file uploads and does not clean them.</p>



<p>If you manage to get the URL of that uploaded SVG file &amp; that file is saved in the same domain of the main website, the exploit is complete.</p>



<p>You can write malicious JS code to dump cookies (for example) wherever you want to.</p>



<p>You can then simply send the SVG URL to any user of that particular website which you are also a part of, and if that user opens it the JS code will execute.</p>



<h2 class="wp-block-heading">How to fix it?</h2>



<p>The fix to the SVG XSS vulnerability is simple.</p>



<p>Let&#8217;s assume that you still want your users to be able to upload SVG files.</p>



<p>In that case, you would need to use an SVG cleaner before you store the uploaded file.</p>



<p>We&#8217;re going to use an SVG cleaner library: <a href="https://github.com/darylldoyle/svg-sanitizer" target="_blank" rel="noreferrer noopener nofollow">daryll/svg-sanitizer</a></p>



<h2 class="wp-block-heading">Code example</h2>



<p>I&#8217;m going to write an extremely simple example to illustrate how this can be solved with ease.</p>



<p>First off, make sure that you download the SVG-sanitizer code from the above SVG cleaner library.</p>



<p>If you use composer, simply require the library into your code.</p>



<p>Let&#8217;s say you have the following upload processing code</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php
/* Load the autoload file from vendor */
require_once './vendor/autoload.php';

/* Check for form submission */
if(!empty($_POST)) {
    $file_extension = explode('.', $_FILES['image']['name']);
    $file_extension = mb_strtolower(end($file_extension));
    $file_temp = $_FILES['image']['tmp_name'];

    /* THIS IS JUST AN EXAMPLE */
    /* Here you typically do your form processing and validations */

    /* Generate a new file name */
    $file_new_name = md5(time(). rand()) . '.' . $file_extension;

    /* Upload the file */
    move_uploaded_file($file_temp, realpath(__DIR__) . '/images/' . $file_new_name);
}
?></pre>



<p>As mentioned in the code, this is just an example. </p>



<p>Normally, you have more validations and error checks before you upload the file.</p>



<h2 class="wp-block-heading">Clean the SVG</h2>



<p>Now, let&#8217;s clean the SVG file with the library that we have imported.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">if($file_extension == 'svg') {
    $svg_sanitizer = new \enshrined\svgSanitize\Sanitizer();
    $dirty_svg = file_get_contents($file_temp);
    $clean_svg = $svg_sanitizer->sanitize($dirty_svg);
    file_put_contents($file_temp, $clean_svg);
}</pre>



<p>This code will only run if the file extension is &#8216;svg&#8217;.</p>



<p>It will take the temporary file which was uploaded.</p>



<p>Then put it through the SVG Cleaner.</p>



<p>And save it back into the initial temporary file.</p>



<h2 class="wp-block-heading">Final code example</h2>



<p>The full PHP code would look something like this:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php
require_once './vendor/autoload.php';

/* Check for form submission */
if(!empty($_POST)) {
    $file_extension = explode('.', $_FILES['image']['name']);
    $file_extension = mb_strtolower(end($file_extension));
    $file_temp = $_FILES['image']['tmp_name'];

    /* THIS IS JUST AN EXAMPLE */
    /* Here you typically do your form processing and validations */

    if($file_extension == 'svg') {
        $svg_sanitizer = new \enshrined\svgSanitize\Sanitizer();
        $dirty_svg = file_get_contents($file_temp);
        $clean_svg = $svg_sanitizer->sanitize($dirty_svg);
        file_put_contents($file_temp, $clean_svg);
    }


    $file_new_name = md5(time(). rand()) . '.' . $file_extension;

    /* Upload the original */
    move_uploaded_file($file_temp, realpath(__DIR__) . '/images/' . $file_new_name);
}
?></pre>



<h2 class="wp-block-heading">Video tutorial</h2>



<p>I have also recorded a video tutorial on how you can implement this library and fix this XSS SVG exploit in under 5 minutes.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="XSS Through SVG File Uploads - How to fix - PHP" width="920" height="518" src="https://www.youtube.com/embed/1YojtYHc-Ng?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Please, make sure that you clean all the SVG file uploads, as otherwise, you are exposing yourself to risk for no reason.</p>



<p>Hope you&#8217;ve found this useful, take care!</p>
<p>The post <a href="https://grohsfabian.com/xss-through-svg-file-uploads-how-to-fix-with-php/">Fixing XSS Through SVG File Uploads PHP</a> appeared first on <a href="https://grohsfabian.com">Grohs Fabian</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://grohsfabian.com/xss-through-svg-file-uploads-how-to-fix-with-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to use PHP Caching with MySQL Queries to improve performance</title>
		<link>https://grohsfabian.com/how-to-use-php-caching-with-mysql-queries-to-improve-performance/</link>
					<comments>https://grohsfabian.com/how-to-use-php-caching-with-mysql-queries-to-improve-performance/#comments</comments>
		
		<dc:creator><![CDATA[grohsfabian]]></dc:creator>
		<pubDate>Mon, 25 Jan 2021 23:21:42 +0000</pubDate>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php caching]]></category>
		<guid isPermaLink="false">https://grohsfabian.com/?p=120</guid>

					<description><![CDATA[<p>I&#8217;m going to show you an easy and efficient way of using PHP Caching to help reduce the database calls and improve the performance of your PHP script. Instead of writing our own caching script and wasting time, we&#8217;re going to use the phpFastCache library to help us with our caching needs. The caching method ... <a title="How to use PHP Caching with MySQL Queries to improve performance" class="read-more" href="https://grohsfabian.com/how-to-use-php-caching-with-mysql-queries-to-improve-performance/" aria-label="Read more about How to use PHP Caching with MySQL Queries to improve performance">Read more</a></p>
<p>The post <a href="https://grohsfabian.com/how-to-use-php-caching-with-mysql-queries-to-improve-performance/">How to use PHP Caching with MySQL Queries to improve performance</a> appeared first on <a href="https://grohsfabian.com">Grohs Fabian</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I&#8217;m going to show you an easy and efficient way of using PHP Caching to help reduce the database calls and improve the performance of your PHP script.</p>



<p>Instead of writing our own caching script and wasting time, we&#8217;re going to use the <a href="https://www.phpfastcache.com/" target="_blank" rel="noreferrer noopener nofollow">phpFastCache</a> library to help us with our caching needs.</p>



<p>The caching method I&#8217;m going to present is <strong>file-based</strong> and is aimed towards <strong>MySQL query results caching</strong>.</p>



<span id="more-120"></span>



<h2 class="wp-block-heading" id="why-use-caching">Why use caching?</h2>



<p>In most cases, MySQL queries are slower than reading files from the storage drive. Now, the vast majority of web hosts offer now SSD storage (like <a href="http://l.grohsfabian.com/namecheap" target="_blank" rel="noreferrer noopener nofollow">Namecheap</a>), which makes it extremely fast.</p>



<ul class="wp-block-list">
<li>Easy to understand &amp; implement</li>



<li>Helps reduce unnecessary database calls</li>



<li>Improves performance</li>
</ul>



<h2 class="wp-block-heading" id="when-to-use-caching">When to use caching?</h2>



<p>In this case, we&#8217;re strictly talking about caching the results of MySQL queries, so I would suggest to look for caching when:</p>



<ul class="wp-block-list">
<li>You&#8217;ve already done the performance improvements directly from the database (table optimizations, proper indexing&#8230;etc) and you want even better performance.</li>



<li>You have dynamic content that doesn&#8217;t change that often.</li>



<li>You use an external MySQL database and queries are taking even longer.</li>



<li>Your server resources are taking too much of a hit.</li>



<li>You simply want to learn and use PHP Caching <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/26a1.png" alt="⚡" class="wp-smiley" style="height: 1em; max-height: 1em;" />.</li>
</ul>



<p>Of course, there are many other reasons on why you should use caching and when to use it, and I&#8217;m not going to go technical on all of them.</p>



<h2 class="wp-block-heading" id="take-a-real-world-example">Take a real world example</h2>



<p>Let&#8217;s take a real world scenario, broken down to a more basic level.</p>



<p>You&#8217;ve got a website, that website holds user profile pages for people and can be accessed like <strong>site.com/profile-name</strong>, just like Facebook, Twitter, Instagram..etc.</p>



<p>Your MySQL database is going to have a table that contains a few columns, like:</p>



<ul class="wp-block-list">
<li>profile_id</li>



<li>username</li>



<li>title</li>



<li>description</li>
</ul>



<p>When someone enters, lets say: <strong>site.com/fabian</strong>, you have a query that asks the database if the <strong>fabian</strong> username is existing and what data to get from it, such as:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

$username = 'Fabian';

$profile = $database->query("SELECT * FROM `profiles` WHERE `username` = '{$username}'")->fetch_object();</pre>



<p>Now, this profile page <strong>can change</strong> when the user is actually changing his username, title, or description, but it is not often that this happens.</p>



<p>If this profile alone gets 10-100 visitors per day, and this is on an extremely small level, the PHP Script above is going to make the same SQL queries to the database 10-100 times.</p>



<p>Until now, there is nothing wrong and nothing to use caching for.</p>



<p>Now, imagine that this <strong>fabian </strong>profile is not the only one, <strong>there are 100,000 or even millions more profiles</strong>. </p>



<p>The above MySQL query is now getting &#8220;expensive&#8221; to run each time a visitor comes to  your profile.</p>



<p>Why? Because MySQL is going to have to search through thousands or millions of other profiles to find the requested profile in order to display it.</p>



<p>Again, I would first suggest you learn about how to properly optimize your queries and tables for better performance.</p>



<h2 class="wp-block-heading" id="improvements-you-re-going-to-see">Improvements you&#8217;re going to see</h2>



<p>If we introduce caching to the logic above, we&#8217;re going to get the following workflow:</p>



<ol class="wp-block-list">
<li>Visitor accesses site.com/fabian</li>



<li>Cache for the fabian profile does not yet exist</li>



<li>MySQL query is executed to search for the fabian profile</li>



<li>The cache for the fabian profile is set</li>



<li>New visitor accesses the profile</li>



<li>Cache now exists</li>



<li>The details of the profile are returned from the cache</li>
</ol>



<p>Reading the data from the file cache is most of the times, in these cases, much faster.</p>



<p><strong>Let&#8217;s take a real-world example</strong> on a $5/month <a href="https://l.grohsfabian.com/digitalocean" target="_blank" rel="noreferrer noopener nofollow">DigitalOcean</a> droplet.</p>



<p>With the same concept I&#8217;ve described above, we&#8217;re going to have:</p>



<ul class="wp-block-list">
<li>2+ million profiles</li>



<li>a basic, cheap host with SSD storage</li>



<li>Ubuntu 20, PHP 7.4, MySQL 8.0</li>
</ul>



<p>The <strong>MySQL query will take about 6-7 seconds</strong> to perform this query. Of course, with proper optimization and indexing, this will be much faster.</p>



<p><strong>Reading the cache</strong> after it is indexed is going to take about <strong>0.0006 seconds</strong>, on average.</p>



<p>Even if your query is highly optimized and is fast, caching will make it so that there is not so much strain on the MySQL server, since reading from a file is most of the times going to be the easiest and fastest way to access the needed data.</p>



<h2 class="wp-block-heading" id="implementing-caching-for-sql-queries">Implementing caching for SQL Queries</h2>



<p>Let&#8217;s get down to the actual code so that you can get started right away.</p>



<p>As mentioned at the beginning of the article, we are going to use <a href="https://github.com/PHPSocialNetwork/phpfastcache/" target="_blank" rel="noreferrer noopener nofollow">phpFastCache</a> as it is a highly respected, used, and secure caching library.</p>



<p>Make sure that you first install phpFastCache and it is ready to go. You can find all the instructions on the GitHub repo, so I won&#8217;t go over them, the easiest would be with Composer.</p>



<p>However you install phpFastCache, make sure to also require it on every page that you&#8217;re going to use, either directly or via composer:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

/* Make sure to properly add your own vendor autoload path */
require_once './vendor/autoload.php';</pre>



<h3 class="wp-block-heading" id="initiating-phpfastcache">Initiating phpFastCache</h3>



<p>Before starting to use the caching library, you&#8217;re going to need some extra lines of code. These lines will set the default configuration for phpFastCache and initiate it so that you&#8217;ll be able to use it.</p>



<p>This initiation should only be done once, on every page that is going to use caching.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

/* Cache adapter for phpFastCache */
$cache_config = new \Phpfastcache\Drivers\Files\Config([
    'path' => realpath(__DIR__) . '/cache', // The folder where the caching will be created
    'securityKey' => 'my-random-security-key', // Can be the name of your project, will be used to create the folder inside the caching path
    'preventCacheSlams' => true,
    'cacheSlamsTimeout' => 20,
    'secureFileManipulation' => true
]);

\Phpfastcache\CacheManager::setDefaultConfig($cache_config);

$cache = \Phpfastcache\CacheManager::getInstance('Files');</pre>



<p>Make sure that the &#8216;path&#8217; that you define for caching is having CHMOD 777, so that files and folders can be created inside of it and manipulated via the PHP code.</p>



<p>There is an easier method to use phpFastCache, as written on the phpFastCache page they have on GitHub. I wouldn&#8217;t recommend that as it doesn&#8217;t have cache slams prevention and it has limited functionality.</p>



<h3 class="wp-block-heading" id="using-phpfastcache-to-cache-a-mysql-query-result">Using phpFastCache to cache a MySQL query result</h3>



<p>As I&#8217;ve explained above, the idea is to cache the query data that you get from the result and to retrieve it on the next requests.</p>



<p>This can be done extremely easily, just by setting up one if condition, as seen below.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

$profile_username = isset($_GET['username']) ? $database->escape_string(filter_var($_GET['username'], FILTER_SANITIZE_STRING)) : null;

* Try to get the cached item based on the requested profile username */
$cache_instance = $cache->getItem('profile?username=' . $profile_username);

/* Check if cache exists */
if(is_null($cache_instance->get())) {

    /* Get data from the database of the requested profile */
    $profile = $database->query("SELECT * FROM `profiles` WHERE `username` = '{$profile_username}'")->fetch_object();

    /* Save the data from the database to the cache */
    $cache->save(
        $cache_instance->set($profile)->expiresAfter(300)
    );

} else {

    /* Return cached data */
    $profile = $cache_instance->get();

}</pre>



<p>Keep in mind, this is just a sample PHP caching snippet on a very basic level.</p>



<p><strong>Here is what is happening:</strong></p>



<p><strong>$profile_username</strong> is the variable responsible for the requested username of the particular profile you want to get from the database.</p>



<p>The <strong>$cache-&gt;getItem()</strong> function requires one parameter, the key of the cache that you want to return. In this case, the key is dynamic based on the actual <strong>$profile_username</strong> variable.</p>



<p>We&#8217;re then checking to see if this particular doesn&#8217;t exist or exists but it is expired. This is the part where we need to make the actual call to the database to get the data that we want.</p>



<p>I am storing all the database details in the <strong>$profile </strong>variable and then simply saving that data into the cache and setting an expiration of 5 minutes (300 seconds) with $cache_instance-&gt;set()-&gt;expiresAfter();</p>



<p>Then, we use $cache-&gt;save() to save configured cache with the particular key that we&#8217;ve asked for in the first place, which is <strong>&#8216;profile?username=&#8217; . $profile_username</strong>.</p>



<p>In this example, I am assuming that you already have your database connection set up and is accessed via the $database variable and that you already load the phpFastCache library, as mentioned in their documentation.</p>



<p><strong>That&#8217;s it.</strong> You&#8217;ve just cached your first SQL Query result with just a few lines of code.</p>



<h3 class="wp-block-heading" id="how-to-test-it">How to test it?</h3>



<p>First of all, I would suggest developing this feature for your PHP script with all the errors enabled, so that you see if you&#8217;ve made any mistakes.</p>



<p>Secondly, you can test out the performance of what you&#8217;ve done with the simple code below:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php
$profile_username = isset($_GET['username']) ? $database->escape_string(filter_var($_GET['username'], FILTER_SANITIZE_STRING)) : null;

/* Set the timer before the script executes */
$time_start = microtime(true);
$method = '';

/* Try to get the cached item based on the requested profile username */
$cache_instance = $cache->getItem('profile?username=' . $profile_username);

/* Check if cache exists */
if(is_null($cache_instance->get())) {

    $method = 'Database';
    
    /* Get data from the database of the requested profile */
    $profile = $database->query("SELECT * FROM `profiles` WHERE `username` = '{$profile_username}'")->fetch_object();

    /* Save the data from the database to the cache */
    $cache->save(
        $cache_instance->set($profile)->expiresAfter(300)
    );

} else {

    $method = 'Cache';

    /* Return cached data */
    $profile = $cache_instance->get();

}

/* Set the time after the script executes */
$time_end = microtime(true);

echo 'Execution time: ' . number_format($time_end - $time_start, 10) . ' seconds via the ' . $method . ' method.';
</pre>



<p>This code is going to output the execution time, including the method used for getting the data (database or cache), so that you can test out the results properly and see the difference.</p>



<h3 class="wp-block-heading" id="things-to-be-careful-about">Things to be careful about</h3>



<p>When you start to cache your queries, you need to make sure that you understand the fact that you also should delete the already existing cache if the data from the database is changing.</p>



<p>Here&#8217;s what I mean by that:</p>



<p>If you set the caching to 5 minutes (300 seconds) and the owner of the profile page goes in the profile settings and changes his title, for example, then you will encounter a problem.</p>



<p>It will then take 5 minutes for the changes to show up, as the requested profile is already cached and showing up the cached results.</p>



<p>This might be a problem in some cases and in some other cases, it doesn&#8217;t make that much of a difference.</p>



<p>In this particular case that I have exemplified above, the change should definitely be seen instantly, even if we&#8217;re using caching.</p>



<p>On the profile settings page, after you successfully save the new details to the database, you&#8217;re simply going to have to run the following snippet of code. This will delete the already existing (if any) cache for the particular profile that was updated:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="php" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;?php

$cache->deleteItem('profile?username=' . $profile_username);</pre>



<p>Make sure that you also initiate the caching system in the pages where you want to delete the cache.</p>



<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>



<p>I would highly recommend you to use caching in this kind of situation, as it will make your PHP scripts much faster and more scalable.</p>



<p>If you have any questions, simply leave a comment, I would be happy to answer and try to help <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f917.png" alt="🤗" class="wp-smiley" style="height: 1em; max-height: 1em;" />.</p>



<p>Hope you&#8217;ve enjoyed this!</p>
<p>The post <a href="https://grohsfabian.com/how-to-use-php-caching-with-mysql-queries-to-improve-performance/">How to use PHP Caching with MySQL Queries to improve performance</a> appeared first on <a href="https://grohsfabian.com">Grohs Fabian</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://grohsfabian.com/how-to-use-php-caching-with-mysql-queries-to-improve-performance/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
