<?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>Debugging Archives ~ Carlos Guzman</title>
	<atom:link href="https://carlosguzman.dev/tag/debugging/feed/" rel="self" type="application/rss+xml" />
	<link>https://carlosguzman.dev/tag/debugging/</link>
	<description>Senior Backend Developer - PHP - WordPress - REST APIs</description>
	<lastBuildDate>Thu, 25 Jun 2020 11:11:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.2</generator>

<image>
	<url>https://carlosguzman.dev/wp-content/uploads/2019/06/favicon.ico</url>
	<title>Debugging Archives ~ Carlos Guzman</title>
	<link>https://carlosguzman.dev/tag/debugging/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Datetime or Timestamp: readability matters</title>
		<link>https://carlosguzman.dev/datetime-or-timestamp-readability-matters/</link>
					<comments>https://carlosguzman.dev/datetime-or-timestamp-readability-matters/#respond</comments>
		
		<dc:creator><![CDATA[Carlos Guzmán]]></dc:creator>
		<pubDate>Fri, 12 Jun 2020 20:39:48 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">https://carlosguzman.dev/?p=153</guid>

					<description><![CDATA[<p>When you are designing the schema of the database for your project and you need to store dates and times, then the question about what data type to use appears. Recently, I started a project to build a REST API and I used timestamps, a total mistake. Later, I was applying to a job and [&#8230;]</p>
<p>The post <a href="https://carlosguzman.dev/datetime-or-timestamp-readability-matters/">Datetime or Timestamp: readability matters</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">When you are designing the schema of the database for your project and you need to store dates and times, then the question about what data type to use appears. Recently, I started a project to build a REST API and I used timestamps, a total mistake. Later, I was applying to a job and again I decided to use timestamps in the project to show my skills. During the interview, the recruiter asked me why I decided to use timestamps and I realized that I didn’t make any analysis for this decision. I just wanted to try it…what a mistake.</p>



<p class="wp-block-paragraph">After this, I decided to investigate the pros and cons for the different options to store dates in a database. There are multiple articles about this topic. I want to highlight this <a rel="noreferrer noopener" aria-label="article where it is explained with details, examples and benchmarks using MySQL (opens in a new tab)" href="https://www.vertabelo.com/blog/what-datatype-should-you-use-to-represent-time-in-mysql-we-compare-datetime-timestamp-and-int/" target="_blank">article where it is explained with details, examples and benchmarks using MySQL</a>. Next is a too short summary about the article:</p>



<ul class="wp-block-list"><li>Using <em>DATETIME</em> allows to make SQL queries using functions related to dates(i.e: WEEKDAY in MySQL) in the SQL server. It allows to use dates from year 1000 to 9999. Queries over <em>DATETIME</em> are faster than queries over <em>TIMESTAMP</em>. The format used to print the <em>DATETIME</em> is user friendly and legible.</li><li>Using <em>TIMESTAMP</em> also allows to make SQL queries using functions related to dates. It allows dates until 2038 only. <em>TIMESTAMP</em> is lighter and it saves 1 byte of storage compared with <em>DATETIME</em>. The format used to print the <em>TIMESTAMP</em> is user friendly and legible.</li><li>Using <em>UNSIGNED INT</em> allows dates until 2106. It is not possible to use CURRENT_TIMESTAMP with this data type. SQL queries over INT are much faster than <em>DATETIME</em> and <em>TIMESTAMP</em>. To use date functions, the integer should be converted to a date(using function FROM_UNIXTIME in MySQL). In this case the SQL queries are slower than <em>DATETIME</em>.</li></ul>



<p class="wp-block-paragraph">One of the disadvantages with <em>TIMESTAMP</em> is the limit of 2038. Personally, I think that the SQL servers will change this in order to preserve compatibility with existing software using this datatype. It is not the same with <em>INT</em> because it is a datatype not intended to be used for dates. However there are integer types using more bytes of storage like <em>BIGINT</em> in MySQL.</p>



<p class="wp-block-paragraph">After my experience using timestamps in a REST API, definitely I will use <em>DATETIME</em> in next projects unless performance and storage are critical. When you are debugging, readability matters. When you see a bunch of numbers that not make sense, then you need to expend time converting those numbers to readable dates. Also working in the frontend, sometimes I needed to understand why I was getting those dates and then again it was stressful to see unintelligible numbers in the API response.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img fetchpriority="high" decoding="async" width="322" height="277" src="https://carlosguzman.dev/wp-content/uploads/2020/06/timestamps-in-api-response.png" alt="datetime or timestamp: readability matters" class="wp-image-155" srcset="https://carlosguzman.dev/wp-content/uploads/2020/06/timestamps-in-api-response.png 322w, https://carlosguzman.dev/wp-content/uploads/2020/06/timestamps-in-api-response-300x258.png 300w" sizes="(max-width: 322px) 100vw, 322px" /><figcaption>Timestamps in a REST API response</figcaption></figure></div>



<p class="wp-block-paragraph">In my opinion, using <em>UNSIGNED INT</em> has sense if the performance of the app is critical <strong>AND</strong> you have one or multiple queries that doesn’t require to use date functions and they are in processes that run frequently in the app.</p>
<p>The post <a href="https://carlosguzman.dev/datetime-or-timestamp-readability-matters/">Datetime or Timestamp: readability matters</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://carlosguzman.dev/datetime-or-timestamp-readability-matters/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Running PHPUnit tests automatically</title>
		<link>https://carlosguzman.dev/running-phpunit-tests-automatically/</link>
					<comments>https://carlosguzman.dev/running-phpunit-tests-automatically/#respond</comments>
		
		<dc:creator><![CDATA[Carlos Guzmán]]></dc:creator>
		<pubDate>Sun, 01 Mar 2020 17:30:52 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">https://carlosguzman.dev/?p=88</guid>

					<description><![CDATA[<p>I have found test-driven development(TDD) a very interesting development methodology. Just recently I have been applying this in the development of a WordPress plugin. One of the issues during the development was wasting time launching tests manually after making changes to the code. You don’t know what you could do and achieve in those few [&#8230;]</p>
<p>The post <a href="https://carlosguzman.dev/running-phpunit-tests-automatically/">Running PHPUnit tests automatically</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">I have found test-driven development(TDD) a very interesting development methodology. Just recently I have been applying this in the development of a WordPress plugin. One of the issues during the development was wasting time launching tests manually after making changes to the code. You don’t know what you could do and achieve in those few seconds. Running PHPUnit tests automatically became important to save those precious seconds. In this post I want to share how to run tests automatically when a change in code is detected.</p>



<p class="wp-block-paragraph">There are multiple options that you could use for running phpunit tests automatically. In example, <a rel="noreferrer noopener" aria-label="phpunit-watcher (opens in a new tab)" href="https://github.com/spatie/phpunit-watcher" target="_blank">phpunit-watcher</a> is a PHP script that you can install in your project easily through composer. In my case, I created <a href="https://github.com/c4rlosguzm4n/watch-and-do">watch-and-do</a>, a bash script and it is now hosted in Github. Honestly I think I didn’t google it well and I didn’t find phpunit-watcher before. But let’s say that I wanted to learn and create a bash script.</p>



<figure class="wp-block-image"><a href="https://carlosguzman.dev/wp-content/uploads/2020/02/console-running-phpunit-automatically.jpg"><img decoding="async" width="1024" height="610" src="https://carlosguzman.dev/wp-content/uploads/2020/02/console-running-phpunit-automatically-1024x610.jpg" alt="console running phpunit automatically" class="wp-image-90" srcset="https://carlosguzman.dev/wp-content/uploads/2020/02/console-running-phpunit-automatically-1024x610.jpg 1024w, https://carlosguzman.dev/wp-content/uploads/2020/02/console-running-phpunit-automatically-300x179.jpg 300w, https://carlosguzman.dev/wp-content/uploads/2020/02/console-running-phpunit-automatically-768x457.jpg 768w, https://carlosguzman.dev/wp-content/uploads/2020/02/console-running-phpunit-automatically.jpg 1280w" sizes="(max-width: 1024px) 100vw, 1024px" /></a><figcaption>Running PHPUnit tests automatically with watch-and-do</figcaption></figure>



<p class="wp-block-paragraph">A testing environment with WordPress configured and running is required in order to run tests for the WordPress plugin. In the official documentation of WordPress, you can find <a href="https://make.wordpress.org/cli/handbook/plugin-unit-tests/">how to create the testing environment for your WordPress plugin</a>.</p>



<p class="wp-block-paragraph">The bash script is based on <a href="https://linux.die.net/man/1/inotifywait">inotifywait</a> to watch and detect changes in the code. This tool can use some filters to notify when a file is created, modified, deleted or moved only:</p>



<pre class="wp-block-code"><code># listen for changes
inotifywait -m -r -q -e modify -e create -e delete -e move --format "%w%f %e" $WATCHDIR</code></pre>



<p class="wp-block-paragraph">When a change is detected, then the script waits for a couple of seconds before launching the tests. Sometimes I am editing multiple files and then I save all of them. With a delay in the script, the test are launched after the last saving instead launching the tests after saving each file:</p>



<pre class="wp-block-code"><code># increase the stock
echo $(( $(cat $STOCK_FILE) + 1 )) &gt; $STOCK_FILE

# sleep for a moment while more changes are detected
sleep $CHANGES_DETECTION_SLEEP

# decrease stock
echo $(( $(cat $STOCK_FILE) - 1 )) &gt; $STOCK_FILE

# if stock is empty (this discard multiple execution)
if [ $(cat $STOCK_FILE) -eq 0 ]
then
    # run tests
    run_tests $@
fi</code></pre>



<p class="wp-block-paragraph">It is important to run the tests in a new process and store its PID because it is used to stop the process if required. Before launching the tests, it is possible that the tests are under execution due to a previous modification of a file. In order to not get conflicts and to not get a mess in the console, it is a good idea to stop the current execution of the tests. We stop the tests using the PID of the process and the kill command with signal SIGTERM. The tests are not stopped immediately, so it is important to wait until they have been stopped:</p>



<pre class="wp-block-code"><code>while [ $LASTPID ] &amp;&amp; [ $LASTPID -gt 0 ] &amp;&amp; (ps -p $LASTPID &gt; /dev/null)
do
    # kill previous testing
    if [ $KILLING -eq 0 ]
    then
        KILLING=1    
        kill -SIGTERM $LASTPID
    fi

    # wait until previous tests are finished
    echo "Wait while current tests are stopped..."
    sleep $TESTS_KILLING_SLEEP
done</code></pre>



<p class="wp-block-paragraph">Finally, when previous tests have been stopped, the new tests are lunched and the PID of its process is stored. The command to run the tests is passed as an argument to the script. In this way the script is not attached to how phpunit is configured in the system:</p>



<pre class="wp-block-code"><code># execute tests
echo "Running command: $@"
$@ &amp;

# store the pid of the thread running the tests
echo $! &gt; $PID_FILE</code></pre>



<p class="wp-block-paragraph">Using the script requires as arguments the folder to watch and the command to run the tests:</p>



<pre class="wp-block-code"><code>$ ./watch-and-do my-base-folder phpunit -v</code></pre>



<p class="wp-block-paragraph">As mentioned before, this script is just an alternative to other tools to watch for changes in your code and run the tests automatically. This bash script is open source and you can find it in Github as <a href="https://github.com/c4rlosguzm4n/watch-and-do">watch-and-do</a>.</p>
<p>The post <a href="https://carlosguzman.dev/running-phpunit-tests-automatically/">Running PHPUnit tests automatically</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://carlosguzman.dev/running-phpunit-tests-automatically/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to see the error logs in WordPress with Docker in Linux</title>
		<link>https://carlosguzman.dev/how-to-see-the-error-logs-in-wordpress-with-docker-in-linux/</link>
					<comments>https://carlosguzman.dev/how-to-see-the-error-logs-in-wordpress-with-docker-in-linux/#comments</comments>
		
		<dc:creator><![CDATA[Carlos Guzmán]]></dc:creator>
		<pubDate>Fri, 24 Jan 2020 17:47:42 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">https://carlosguzman.dev/?p=48</guid>

					<description><![CDATA[<p>Recently I was working in the development of a WordPress plugin and I didn&#8217;t find an easy way to see the error logs in WordPress with Docker. I started to read and learn about Docker some few time ago. I created a WordPress development instance using the official Docker image for WordPress in Docker Hub. [&#8230;]</p>
<p>The post <a href="https://carlosguzman.dev/how-to-see-the-error-logs-in-wordpress-with-docker-in-linux/">How to see the error logs in WordPress with Docker in Linux</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Recently I was working in the development of a WordPress plugin and I didn&#8217;t find an easy way to see the error logs in WordPress with Docker. I started to read and learn about Docker some few time ago. I created a WordPress development instance using <a rel="noreferrer noopener" aria-label="the official Docker image for WordPress in DockerHub (opens in a new tab)" href="https://hub.docker.com/_/wordpress" target="_blank">the official Docker image for WordPress in Docker Hub</a>. In some cases, you want to see the log of errors and do not activate the debug mode in WordPress. In example, a plugin can generate warnings that make difficult to debug and that could break responses for Ajax requests in your site.</p>



<p class="wp-block-paragraph">My first attempt to see the error logs was to login in a bash session it the Docker container. Then I searched for the error log file but the errors are sent to the I/O stream STDERR by default.<mark class="annotation-text annotation-text-yoast" id="annotation-text-4058d5b7-636c-4a18-bcd5-ab1e309368af"></mark></p>



<figure class="wp-block-image"><a href="https://carlosguzman.dev/wp-content/uploads/2020/01/default-error-logs-wordpress-docker.jpg"><img decoding="async" width="892" height="134" src="https://carlosguzman.dev/wp-content/uploads/2020/01/default-error-logs-wordpress-docker.jpg" alt="Default configuration of error logs for WordPress with Docker" class="wp-image-60" srcset="https://carlosguzman.dev/wp-content/uploads/2020/01/default-error-logs-wordpress-docker.jpg 892w, https://carlosguzman.dev/wp-content/uploads/2020/01/default-error-logs-wordpress-docker-300x45.jpg 300w, https://carlosguzman.dev/wp-content/uploads/2020/01/default-error-logs-wordpress-docker-768x115.jpg 768w" sizes="(max-width: 892px) 100vw, 892px" /></a><figcaption>Default configuration of error logs for WordPress with Docker</figcaption></figure>



<p class="wp-block-paragraph">Instead to create a custom image to change this configuration, I tried with the <a rel="noreferrer noopener" aria-label="Docker cli tool to access to the logs of the container (opens in a new tab)" href="https://docs.docker.com/engine/reference/commandline/logs/" target="_blank">Docker cli tool to access to the logs of the container</a>. Using <code>docker logs ID_CONTAINER</code>, I was able to see the logs of the web server. It was progress but it wasn&#8217;t what I want. I got all logs entries of the web server including access and warning entries. It would be difficult to spot the error entries easily in a website loading multiple resources and doing multiple Ajax requests.</p>



<figure class="wp-block-image"><a href="https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs.jpg"><img loading="lazy" decoding="async" width="824" height="500" src="https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs.jpg" alt="Show logs of the Docker WordPress image container." class="wp-image-54" srcset="https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs.jpg 824w, https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-300x182.jpg 300w, https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-768x466.jpg 768w" sizes="auto, (max-width: 824px) 100vw, 824px" /></a><figcaption>Show logs of the Docker WordPress image container.</figcaption></figure>



<h2 class="wp-block-heading">The solution</h2>



<p class="wp-block-paragraph">If we discard the output sent to the standard stream, then the access entries are gone. So using <code>docker logs -f ID_CONTAINER &gt;/dev/null</code>, we get only the entries sent to the error stream. Most of the entries here are the useful entries for debugging, they are the warning and error messages. The option -f in docker logs command is to follow and refresh automatically the logs in the console.</p>



<figure class="wp-block-image"><a href="https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-without-access-entries.jpg"><img loading="lazy" decoding="async" width="828" height="478" src="https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-without-access-entries.jpg" alt="" class="wp-image-56" srcset="https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-without-access-entries.jpg 828w, https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-without-access-entries-300x173.jpg 300w, https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-without-access-entries-768x443.jpg 768w" sizes="auto, (max-width: 828px) 100vw, 828px" /></a><figcaption>Show entries sent to the error stream only</figcaption></figure>



<h3 class="wp-block-heading">Extra tip</h3>



<p class="wp-block-paragraph">If you want to see the error messages only without changing the error reporting directive, you can use the <em>grep</em> tool to filter the other entries. Using <code>docker logs -f ID_CONTAINER 2&gt;&amp;1 &gt;/dev/null | grep -i error</code>, the entries are filtered to display only the lines with the error word in them. This command replaces the output of the standard stream with the output of the error stream. Then <em>grep</em> filters the content. The option -i in the <em>grep</em> command is to be case insensitive in the search.</p>



<figure class="wp-block-image"><a href="https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-only-errors.jpg"><img loading="lazy" decoding="async" width="828" height="341" src="https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-only-errors.jpg" alt="Show only error logs of WordPress with Docker" class="wp-image-57" srcset="https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-only-errors.jpg 828w, https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-only-errors-300x124.jpg 300w, https://carlosguzman.dev/wp-content/uploads/2020/01/console-wordpress-docker-logs-only-errors-768x316.jpg 768w" sizes="auto, (max-width: 828px) 100vw, 828px" /></a><figcaption>Show only error logs of WordPress with Docker</figcaption></figure>



<p class="wp-block-paragraph">Maybe it isn&#8217;t the most elegant but at least it is an effective way to see the error logs in WordPress with Docker.</p>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://carlosguzman.dev/how-to-see-the-error-logs-in-wordpress-with-docker-in-linux/">How to see the error logs in WordPress with Docker in Linux</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://carlosguzman.dev/how-to-see-the-error-logs-in-wordpress-with-docker-in-linux/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk
Database Caching 3/58 queries in 0.039 seconds using Disk

Served from: carlosguzman.dev @ 2026-07-21 08:04:02 by W3 Total Cache
-->