<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Chris Armitage</title>
    <description>The latest articles on DEV Community by Chris Armitage (@chrisarmitage).</description>
    <link>https://dev.to/chrisarmitage</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F667122%2Fdfaec52e-3718-4083-9474-4b231ad6f4af.jpeg</url>
      <title>DEV Community: Chris Armitage</title>
      <link>https://dev.to/chrisarmitage</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chrisarmitage"/>
    <language>en</language>
    <item>
      <title>Teaching an old dog new tricks: Datastax's Summer Sessions</title>
      <dc:creator>Chris Armitage</dc:creator>
      <pubDate>Sat, 31 Jul 2021 21:06:41 +0000</pubDate>
      <link>https://dev.to/chrisarmitage/teaching-an-old-dog-new-tricks-datastax-s-summer-sessions-40md</link>
      <guid>https://dev.to/chrisarmitage/teaching-an-old-dog-new-tricks-datastax-s-summer-sessions-40md</guid>
      <description>&lt;p&gt;Many years ago I decided to shift from being a full-stack developer and focused just on back-end development. This meant leaving behind jquery (and it's callback hell) and IE6 patch code. And it was wonderful!&lt;/p&gt;

&lt;p&gt;When I switched jobs a couple of years ago, I was exposed to Vue and webpack for the first time, and realised front-end development has progressed quite a lot in those years. Then I heard about Jamstack, Netlify, serverless React apps, and realised there was now a major gap in my skillset as a developer. I've already taken part in various Datastax workshops whilst working towards my Cassandra certification, and was somewhat hyped when I saw they were running a 3-week frontend development course.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Summer Sessions course
&lt;/h2&gt;

&lt;p&gt;Over the three weeks, we developed a ToDo list, a TikTok clone, and a Netflix clone. The front-end code was written in React, with the vast majority being done for us. What we focussed on was setting up the Astra database (using the REST, Collection, and GraphQL interfaces), learning how to use those APIs, using Gitpod (never used it before, it's great!), running Netlify locally, then deploying to Netlify prod.&lt;/p&gt;

&lt;h2&gt;
  
  
  The result?
&lt;/h2&gt;

&lt;p&gt;I've had my eyes opened to the Jamstack and the power it can bring to bear. My skills lie in the &lt;code&gt;A&lt;/code&gt; of Jam, the service APIs. But with what I've learnt over these three weeks, I reckon I could take on making some basic front-end apps to consume those APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;p&gt;If you want to see for yourself, the recording from the third workshop, covering how to create a Netflix clone, is available at &lt;a href="https://www.youtube.com/watch?v=4WmafdS66Xo"&gt;https://www.youtube.com/watch?v=4WmafdS66Xo&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>If you're experimenting with pcntl_signal, don't use sleep()</title>
      <dc:creator>Chris Armitage</dc:creator>
      <pubDate>Wed, 14 Jul 2021 16:28:25 +0000</pubDate>
      <link>https://dev.to/chrisarmitage/if-you-re-experimenting-with-pcntlsignal-don-t-use-sleep-36de</link>
      <guid>https://dev.to/chrisarmitage/if-you-re-experimenting-with-pcntlsignal-don-t-use-sleep-36de</guid>
      <description>&lt;p&gt;I've been tinkering with my own PHP micro framework (yes, everyone does, it's a right of passage) and wanted to make some nice queue listener functionality. I've been playing with the likes of AMQP and Kafka, and wanted the listener to shutdown gracefully. I'd never used the &lt;code&gt;pcntl&lt;/code&gt; library before, so it seemed like a good time to learn.&lt;/p&gt;

&lt;p&gt;This isn't a post about the inner workings of &lt;a href="https://www.php.net/manual/en/book.pcntl"&gt;pcntl&lt;/a&gt;, but it does reveal a gotcha that caused me do doubt my sanity.&lt;/p&gt;

&lt;p&gt;In brief, the &lt;code&gt;pcntl_signal&lt;/code&gt; command allows you to intercept a CTRL-C from the command line. You use it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nb"&gt;pcntl_signal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SIGINT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// This will be executed on a CTRL-C, and the script won't terminate&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The general goal is you switch to a graceful shutdown state, finish the active queue job, and then terminate. I didn't have any real code behind this, so the job worker was a simple &lt;code&gt;sleep(5)&lt;/code&gt; to simulate a real-world process. Everything looked good, but it just would not work. As soon as I tried to terminate the script, it actually terminated, it didn't finish the job. No matter what I fiddled with or changed, it just would not finish that job.&lt;/p&gt;

&lt;p&gt;Except.. well... it was doing...&lt;/p&gt;

&lt;p&gt;What I hadn't realised was this buried away in the &lt;a href="https://www.php.net/manual/en/function.sleep.php"&gt;PHP docs&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If the call was interrupted by a signal, sleep() returns a non-zero value.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The signal was being picked up by my custom &lt;code&gt;pcntl_signal&lt;/code&gt; handler, but it was also immediately ending the &lt;code&gt;sleep&lt;/code&gt; command. It was the placeholder code that was failing.&lt;/p&gt;

&lt;p&gt;So, if you want to learn &lt;code&gt;pcntl&lt;/code&gt; (and I may just post some more about what you can do with it), use a snippet like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;microtime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$now&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;microtime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nv"&gt;$target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// noop&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That will cause your script to wait for 5 seconds and won't be interrupted by the CTRL-C.&lt;/p&gt;

</description>
      <category>php</category>
      <category>firstpost</category>
    </item>
  </channel>
</rss>
