<?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>Forem: Václav Makeš</title>
    <description>The latest articles on Forem by Václav Makeš (@vaclav_makes).</description>
    <link>https://forem.com/vaclav_makes</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%2F782612%2Fe2ca1f33-b42a-48a0-ac01-8fc7fe6c3b1b.jpeg</url>
      <title>Forem: Václav Makeš</title>
      <link>https://forem.com/vaclav_makes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/vaclav_makes"/>
    <language>en</language>
    <item>
      <title>How to use the --haproxy-protocol option in Guzzle library?</title>
      <dc:creator>Václav Makeš</dc:creator>
      <pubDate>Sun, 24 Sep 2023 14:25:33 +0000</pubDate>
      <link>https://forem.com/vaclav_makes/how-to-use-the-haproxy-protocol-option-in-guzzle-library-46gh</link>
      <guid>https://forem.com/vaclav_makes/how-to-use-the-haproxy-protocol-option-in-guzzle-library-46gh</guid>
      <description>&lt;p&gt;I needed the &lt;a href="https://github.com/curl/curl/commit/6baeb6df35d24740c55239f24b5fc4ce86f375a5"&gt;--haproxy-protocol&lt;/a&gt; option from the &lt;code&gt;curl&lt;/code&gt; library to call the request. Within curl this option works great. But how to achieve the same in the PHP library Guzzle?&lt;/p&gt;

&lt;p&gt;First, we needed to verify that the option exists in the library itself. As of PHP version 7.3, there is a constant &lt;a href="https://www.php.net/manual/en/function.curl-setopt.php"&gt;CURLOPT_HAPROXYPROTOCOL&lt;/a&gt; that does the same thing. The call then looks 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;$ch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;curl_init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nb"&gt;curl_setopt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;CURLOPT_HAPROXYPROTOCOL&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="c1"&gt;// ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second question was how to use this option within the Guzzle library. While &lt;a href="https://docs.guzzlephp.org/en/stable/request-options.html"&gt;documentation&lt;/a&gt; does not describe the option, it is possible to set the &lt;code&gt;curl&lt;/code&gt; configuration. The library deliberately does not show this setting &lt;a href="https://github.com/guzzle/guzzle/pull/3160"&gt;because it breaks&lt;/a&gt; the abstraction that Guzzle provides.&lt;/p&gt;

&lt;p&gt;The whole call then looks 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;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'GET'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'curl'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;CURLOPT_HAPROXYPROTOCOL&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other options can be added to the &lt;code&gt;curl&lt;/code&gt; field, as described in the PHP documentation for the &lt;a href="https://www.php.net/manual/en/function.curl-setopt.php"&gt;curl_setopt&lt;/a&gt; function.&lt;/p&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Sending messages using Slack Webhooks</title>
      <dc:creator>Václav Makeš</dc:creator>
      <pubDate>Wed, 29 Dec 2021 14:55:27 +0000</pubDate>
      <link>https://forem.com/vaclav_makes/sending-messages-using-slack-webhooks-jaa</link>
      <guid>https://forem.com/vaclav_makes/sending-messages-using-slack-webhooks-jaa</guid>
      <description>&lt;p&gt;&lt;a href="https://api.slack.com/messaging/webhooks"&gt;Slack documentation&lt;/a&gt; has part about sending messages with webhooks.&lt;/p&gt;

&lt;p&gt;It works great, but there is missing information about details. We can send custom message with emoji, username and selected channel.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"My message."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"channel"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"notifications_channel"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"username"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"My custom robot name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"icon_emoji"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"rocket"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you send it from script or CI server you can use &lt;code&gt;curl&lt;/code&gt; in format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s1"&gt;'Content-type: application/json'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--data&lt;/span&gt; &lt;span class="s2"&gt;"{'text':'My message.', 'channel':'notifications_channel', 'username':'My custom robot name', 'icon_emoji':'rocket'}"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nv"&gt;$SLACK_WEBHOOK_URL&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How message in Slack looks? First message is ours, second is from Trello application for comparation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kbyUDB70--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ojw7d3isthhklm5lj0yt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kbyUDB70--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ojw7d3isthhklm5lj0yt.png" alt="Custom Slack message send with webhook" width="634" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
