{"id":50127,"date":"2020-08-30T03:01:58","date_gmt":"2020-08-29T17:01:58","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=50127"},"modified":"2020-08-29T20:55:06","modified_gmt":"2020-08-29T10:55:06","slug":"chat-no-sockets-sms-invitation-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/chat-no-sockets-sms-invitation-tutorial\/","title":{"rendered":"Chat No Sockets SMS Invitation Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Chat No Sockets SMS Invitation Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/chat_sms_invitation.jpg\" title=\"Chat No Sockets SMS Invitation Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Chat No Sockets SMS Invitation Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='Chat No Sockets Session Tutorial' href='#cnsst'>Chat No Sockets Session Tutorial<\/a> gives us an opportunity to become more &#8220;granular&#8221; with our examination of nuances to &#8230;<\/p>\n<ul>\n<li>the web application&#8217;s &#8220;surfing the web&#8221; look and aesthetics (first look) and usage practicalities (involving button disabling\/enabling at appropriate places in the PHP code (writing Javascript logic)) &#8230; and &#8230; a bit gobsmacking to us &#8230;<\/li>\n<li>the need to place a two step logic &#8220;tidy up&#8221; of obsolete files when dealing with SMS Invitations (to Chat)<\/li>\n<\/ul>\n<p> &#8230; the latter being that we discovered that &#8230;<\/p>\n<ul>\n<li>between the point an inviter opens their SMS Messaging app with a populated message that is the URL our Chat web application wants the inviter to send &#8230; and &#8230;<\/li>\n<li>that inviter typing the carriage return character that &#8220;renders&#8221; that SMS that is sent to the invitee &#8230; but &#8230;<\/li>\n<li>before the invitee even sees the SMS<\/li>\n<\/ul>\n<p> &#8230; that URL &#8220;render&#8221; causes an (unexpected to us) real visit of our web server code, and we need to just let the &#8220;look of&#8221; the &#8220;resultant SMS webpage&#8221; through at this point, but leave &#8220;the implications&#8221; for the next time this &#8220;SMS webpage&#8221; is asked for when the invitee clicks\/taps the SMS link they receive from the inviter.  The timing of all this is controlled in the logic by the existence of a (what used to be exclusively) &#8220;chat_*.line&#8221; file, <font color=blue>but we now need (to allow for &#8220;chat_*.lin2&#8221; then &#8220;chat_*.line&#8221;)<\/font> as per &#8230;<\/p>\n<table style='width:100%;font-size:8px;'>\n<tr>\n<th>On clicking the &#8220;Invite&#8221; button, having filled out the &#8220;SMS number&#8221; field (rather than the Email one)<\/th>\n<\/tr>\n<tr>\n<td>\n  function butlogic() {<br \/>\n    if (document.getElementById(&#8216;isms&#8217;).value.trim() != &#8221;) {<br \/>\n     document.getElementById(&#8216;jchild&#8217;).src=document.URL.split(&#8216;#&#8217;)[0].split(&#8216;?&#8217;)[0] + &#8216;?sid=&#8221; . $enduring . &#8220;&#038;address=&#8217; + encodeURIComponent(document.getElementById(&#8216;isms&#8217;).value<font color=blue> + &#8216;#&#8217;<\/font>) + &#8216;&#038;ipaddress=&#8217; + encodeURIComponent(&#8216;&#8221; . $sra . &#8220;&#8216;) + &#8216;&#038;ichat=&#8217; + encodeURIComponent(document.getElementById(&#8216;ichat&#8217;).value);<br \/>\n     var wasasms=document.getElementById(&#8216;asms&#8217;).href;<br \/>\n     if (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n     document.getElementById(&#8216;asms&#8217;).href=(document.getElementById(&#8216;asms&#8217;).href.replace(&#8216;:&#038;&#8217;,&#8217;:&#8217; + document.getElementById(&#8216;isms&#8217;).value + &#8216;&#038;&#8217;) + encodeURIComponent(document.URL.split(&#8216;#&#8217;)[0].split(&#8216;?&#8217;)[0]) + encodeURIComponent(&#8216;?address=&#8217; + dummyencodeURIComponent(encodeURIComponent(document.getElementById(&#8216;isms&#8217;).value))<font color=blue> + &#8216;#&#8217;<\/font>));<br \/>\n     } else {<br \/>\n     document.getElementById(&#8216;asms&#8217;).href=(document.getElementById(&#8216;asms&#8217;).href.replace(&#8216;:&#038;&#8217;,&#8217;:&#8217; + document.getElementById(&#8216;isms&#8217;).value + &#8216;&#038;&#8217;) + encodeURIComponent(document.URL.split(&#8216;#&#8217;)[0].split(&#8216;?&#8217;)[0]) + encodeURIComponent(&#8216;?address=&#8217; + encodeURIComponent(encodeURIComponent(document.getElementById(&#8216;isms&#8217;).value))<font color=blue> + &#8216;#&#8217;<\/font>));<br \/>\n     }<br \/>\n     document.getElementById(&#8216;asms&#8217;).click();<br \/>\n     document.getElementById(&#8216;asms&#8217;).href=wasasms;<br \/>\n    } else if (document.getElementById(&#8216;iemail&#8217;).value.indexOf(&#8216;@&#8217;) != -1) {<br \/>\n     document.getElementById(&#8216;jchild&#8217;).src=document.URL.split(&#8216;#&#8217;)[0].split(&#8216;?&#8217;)[0] + &#8216;?sid=&#8221; . $enduring . &#8220;&#038;address=&#8217; + encodeURIComponent(document.getElementById(&#8216;iemail&#8217;).value) + &#8216;&#038;ipaddress=&#8217; + encodeURIComponent(&#8216;&#8221; . $sra . &#8220;&#8216;) + &#8216;&#038;ichat=&#8217; + encodeURIComponent(document.getElementById(&#8216;ichat&#8217;).value);<br \/>\n     document.getElementById(&#8216;aemail&#8217;).href=(document.getElementById(&#8216;aemail&#8217;).href.replace(&#8216;:?&#8217;,&#8217;:&#8217; + document.getElementById(&#8216;iemail&#8217;).value + &#8216;?&#8217;) + encodeURIComponent(document.URL.split(&#8216;#&#8217;)[0].split(&#8216;?&#8217;)[0]) + encodeURIComponent(&#8216;?address=&#8217; + encodeURIComponent(document.getElementById(&#8216;iemail&#8217;).value)));<br \/>\n     document.getElementById(&#8216;aemail&#8217;).click();<br \/>\n     document.getElementById(&#8216;aemail&#8217;).href=wasaemail;<br \/>\n    }<br \/>\n  }\n<\/td>\n<\/tr>\n<tr>\n<th>Where the child iframe call above lobs onto in order to create an interim file<\/th>\n<\/tr>\n<tr>\n<td>\n} else if (isset($_GET[&#8216;address&#8217;]) &#038;&#038; isset($_GET[&#8216;ipaddress&#8217;])) {<br \/>\n   <font color=blue>if (strpos(str_replace(&#8220;@&#8221;,&#8221;&#8221;,str_replace(&#8220;+&#8221;,&#8221; &#8220;,urldecode($_GET[&#8216;address&#8217;]))), &#8220;#&#8221;) !== false) {<br \/>\n   file_put_contents(&#8220;chat_&#8221; . explode(&#8220;#&#8221;, str_replace(&#8220;@&#8221;,&#8221;&#8221;,str_replace(&#8220;+&#8221;,&#8221; &#8220;,urldecode($_GET[&#8216;address&#8217;]))))[0] . &#8220;__&#8221; . str_replace(&#8220;+&#8221;,&#8221; &#8220;,urldecode($_GET[&#8216;ipaddress&#8217;])) . &#8220;.RLS&#8221;, str_replace(&#8220;+&#8221;,&#8221; &#8220;,urldecode($_GET[&#8216;ichat&#8217;])));<br \/>\n   } else {<\/font><br \/>\n   file_put_contents(&#8220;chat_&#8221; . <font color=blue>explode(&#8220;#&#8221;, <\/font>str_replace(&#8220;@&#8221;,&#8221;&#8221;,str_replace(&#8220;+&#8221;,&#8221; &#8220;,urldecode($_GET[&#8216;address&#8217;])))<font color=blue>)[0]<\/font> . &#8220;__&#8221; . str_replace(&#8220;+&#8221;,&#8221; &#8220;,urldecode($_GET[&#8216;ipaddress&#8217;])) . &#8220;.rls&#8221;, str_replace(&#8220;+&#8221;,&#8221; &#8220;,urldecode($_GET[&#8216;ichat&#8217;])));<br \/>\n   <font color=blue>}<\/font><br \/>\n   exit;\n<\/td>\n<\/tr>\n<tr>\n<th>Where the &#8220;command line&#8221; usage part does its bit to appropriately rename those interim files<\/th>\n<\/tr>\n<tr>\n<td>\nif ($argv) {  \/\/ command line &#8230;<br \/>\n    $cfindings=&#8221;&#8221;;<br \/>\n    $goes=0;<br \/>\n    $howmanygoes=&#8221;-1&#8243;;<br \/>\n    $par=getenv(&#8220;TERM&#8221;); \/\/ thanks to https:\/\/stackoverflow.com\/questions\/3214935\/can-a-bash-script-tell-if-its-being-run-via-cron<br \/>\n    if (&#8220;$par&#8221; == &#8220;&#8221; || &#8220;$par&#8221; == &#8220;dummy&#8221;) {  \/\/ via cron<br \/>\n      $cfindings1=exec(&#8220;crontab -l | grep &#8216;php_listener&#8217; | grep -v &#8216;grep&#8217; | cut -d &#8216; &#8216; -f 1&#8221;);<br \/>\n      $cfindings2=exec(&#8220;crontab -l | grep &#8216;php_listener&#8217; | grep -v &#8216;grep&#8217; | cut -d &#8216; &#8216; -f 2&#8221;);<br \/>\n      $cfindings3=exec(&#8220;crontab -l | grep &#8216;php_listener&#8217; | grep -v &#8216;grep&#8217; | cut -d &#8216; &#8216; -f 3&#8221;);<br \/>\n      $cfindings4=exec(&#8220;crontab -l | grep &#8216;php_listener&#8217; | grep -v &#8216;grep&#8217; | cut -d &#8216; &#8216; -f 4&#8221;);<br \/>\n      $cfindings5=exec(&#8220;crontab -l | grep &#8216;php_listener&#8217; | grep -v &#8216;grep&#8217; | cut -d &#8216; &#8216; -f 5&#8221;);<br \/>\n      if (strpos($cfindings1, &#8220;*\/&#8221;) !== false) {<br \/>\n        $howmanygoes=12 * explode(&#8220;*\/&#8221;, $cfindings1)[1];<br \/>\n      } else if (strpos($cfindings2, &#8220;*\/&#8221;) !== false) {<br \/>\n        $howmanygoes=720 * explode(&#8220;*\/&#8221;, $cfindings2)[1];<br \/>\n      } else if (strpos($cfindings3, &#8220;*\/&#8221;) !== false) {<br \/>\n        $howmanygoes=17280 * explode(&#8220;*\/&#8221;, $cfindings3)[1];<br \/>\n      }<br \/>\n    }<br \/>\n    while (1) {<br \/>\n    foreach (glob(dirname(__FILE__) . &#8220;\/chat_*.rls&#8221;) as $ourfilename) {<br \/>\n      rename($ourfilename, explode(&#8220;.rls&#8221;, $ourfilename)[0] . &#8220;.line&#8221;);<br \/>\n    }<br \/>\n    <font color=blue>foreach (glob(dirname(__FILE__) . &#8220;\/chat_*.RLS&#8221;) as $ourfilename) {<br \/>\n      rename($ourfilename, explode(&#8220;.RLS&#8221;, $ourfilename)[0] . &#8220;.lin2&#8221;);<br \/>\n    }<\/font><br \/>\n    if ($howmanygoes &gt;= 0) { $goes++; if ($goes &gt;= $howmanygoes) {  exit; } }<br \/>\n    sleep(5);<br \/>\n    }<br \/>\n    exit;<br \/>\n}\n<\/td>\n<\/tr>\n<tr>\n<th>Where the &#8220;command line&#8221; usage part&#8217;s renamed file is found by the web application and the two step deletion is needed<\/th>\n<\/tr>\n<tr>\n<td>\n  } else {  \/\/ here from email or SMS link<br \/>\n    $sra=&#8221;&#8221;;<br \/>\n    $cont=&#8221;&#8221;;<br \/>\n    foreach (glob(&#8220;chat_&#8221; . str_replace(&#8220;@&#8221;,&#8221;&#8221;,str_replace(&#8220;+&#8221;,&#8221; &#8220;,urldecode($_GET[&#8216;address&#8217;]))) . &#8220;__*.lin<font color=blue>*<\/font>&#8220;) as $ourfilename) {<br \/>\n      $sra=explode(&#8220;.&#8221;,explode(&#8220;chat_&#8221; . str_replace(&#8220;@&#8221;,&#8221;&#8221;,str_replace(&#8220;+&#8221;,&#8221; &#8220;,urldecode($_GET[&#8216;address&#8217;]))) . &#8220;__&#8221;, $ourfilename)[1])[0];<br \/>\n      $scont=file_get_contents($ourfilename);<br \/>\n      $cont=$scont . &#8220;&lt;br&gt;&#8221;;<br \/>\n      if (trim($scont) != &#8220;&#8221;) { $scont=&#8217; &#8230; starting with &#8220;&#8216; . file_get_contents($ourfilename) . &#8216;&#8221;&#8216;; }<br \/>\n      <font color=blue>if (strpos($ourfilename, &#8220;.lin2&#8221;) !== false) {<br \/>\n      rename($ourfilename, explode(&#8220;.lin2&#8221;, $ourfilename)[0] . &#8220;.line&#8221;);<br \/>\n      $datait=&#8221; data-&#8220;;<br \/>\n      } else {<\/font><br \/>\n      unlink($ourfilename);<br \/>\n      <font color=blue>}<\/font><br \/>\n    }<br \/>\n   echo &#8220;&lt;!doctype html&gt;<br \/>\n   \/\/ etcetera etcetera etcetera<br \/>\n   &lt;body <font color=blue>&#8221; . $datait . &#8220;<\/font>onload=&#8217;onlis();&#8217;&gt;<br \/>\n   \/\/ etcetera etcetera etcetera<br \/>\n   &#8220;;\n<\/td>\n<\/tr>\n<\/table>\n<p>So yet again, feel free to try <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php--GETME\" title=\"php_listener.php\">the changed (including &#8220;session&#8221; logic)<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php--GETME\" title=\"php_listener.php\">php_listener.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php\" title=\"Click picture\">chat web application<\/a> &#8220;third draft&#8221;.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/chat-no-sockets-sms-invitation-tutorial\/'>Chat No Sockets SMS Invitation Tutorial<\/a>.<\/p>\n\n\n\n\n\n<hr>\n\n\n\n\n\n<p id='cnsst'>Previous relevant <a target=_blank title='Chat No Sockets Session Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/chat-no-sockets-session-tutorial\/'>Chat No Sockets Session Tutorial<\/a> is shown below.<\/p>\n\n\n\n[caption id=\"\" align=\"alignnone\" width=\"220\" caption=\"Chat No Sockets Session Tutorial\"]<a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Chat No Sockets Session Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/chat_session.jpg\" title=\"Chat No Sockets Session Tutorial\"  \/><\/a>[\/caption]\n\n\n\n<p>Back from the \"command line\" PHP usage of yesterday's <a title='Chat No Sockets Cron Tutorial' href='#cnsct'>Chat No Sockets Cron Tutorial<\/a> that day's thinking about how to improve the \"surfing the net\" parts of the Chat web application we're developing got us starting to involve PHP ...<\/p>\n\n\n\n<code>\n<a target=_blank title='PHP sessions' href='https:\/\/www.php.net\/manual\/en\/reserved.variables.session.php'>Sessions<\/a>\n<\/code>\n\n\n\n<p> ... and can't they just be really useful as the <font color=blue>identifying methodology<\/font> to hone in on a webpage session of interest, and exclude all irrelevant others ...<\/p>\n\n\n\n&lt;?php\n<code>\n<font color=blue>session_start();\n$enduring='' . session_id();\nif (isset($_GET['sid'])) {\n  $enduring=str_replace(\"+\",\" \",urldecode($_GET['sid']));\n} else if (isset($_POST['sid'])) {\n  $enduring=str_replace(\"+\",\" \",urldecode($_POST['sid']));\n}\n$dbit=' data-oe=\"\" ';<\/font>\n<br \/>\nfunction server_remote_addr() {\n    <font color=blue>global $enduring;<\/font>\n    $rma = $_SERVER['REMOTE_ADDR'];\n    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);\n    \/\/ you can add different browsers with the same way ..\n    if(preg_match('\/(opr)[ \\\/]([\\w.]+)\/', $ua))\n            $rma = '000'.$rma;\n    elseif(preg_match('\/(chromium)[ \\\/]([\\w.]+)\/', $ua))\n            $rma = '000000'.$rma;\n    elseif(preg_match('\/(chrome)[ \\\/]([\\w.]+)\/', $ua))\n            $rma = '00000'.$rma;\n    elseif(preg_match('\/(safari)[ \\\/]([\\w.]+)\/', $ua))\n            $rma = '0000'.$rma;\n    elseif(preg_match('\/(opera)[ \\\/]([\\w.]+)\/', $ua))\n            $rma = '000'.$rma;\n    elseif(preg_match('\/(msie)[ \\\/]([\\w.]+)\/', $ua))\n            $rma = '00'.$rma;\n    elseif(preg_match('\/(mozilla)[ \\\/]([\\w.]+)\/', $ua))\n            $rma = '0'.$rma;\n    return str_replace(\".\", \"x\", str_replace(\":\", \"x\", $rma<font color=blue> . $enduring<\/font>));\n}\n<\/code>\n?&gt;\n\n\n\n<p> ... the only nuance being that iframe children get their session IDs mapped to that of the parent via that \"sid\" argument above.<\/p>\n\n\n\n\n\n<p>And so today's work represents a \"shoring up\" day for the basis for a Chat, and a relief that this \"better honing\" also meant that we no longer needed to tweak those pesky $_SERVER['HTTP_USER_AGENT'] combinations (a dark art indeed).<\/p>\n\n\n\n\n\n<p>So again, feel free to try <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php--GETME\" title=\"php_listener.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php--GETME\" title=\"php_listener.php\">php_listener.php<\/a>'s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php\" title=\"Click picture\">chat web application<\/a> \"third draft\".<\/p>\n\n\n\n<!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/chat-no-sockets-session-tutorial\/'>Chat No Sockets Session Tutorial<\/a>.<\/p-->\n<hr>\n<p id='cnsct'>Previous relevant <a target=_blank title='Chat No Sockets Cron Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/chat-no-sockets-cron-tutorial\/'>Chat No Sockets Cron Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Chat No Sockets Cron Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/chat_cron.gif\" title=\"Chat No Sockets Cron Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Chat No Sockets Cron Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='Chat No Sockets Primer Tutorial' href='#cnspt'>Chat No Sockets Primer Tutorial<\/a> had a &#8220;command line&#8221; PHP usage component, we wonder whether you noticed?   We intend to keep this arrangement for our &#8220;no sockets&#8221; Chat web application.  It will not function as that &#8220;Chat&#8221; without the command line part of the &#8220;equation&#8221; being activated.  You might think of it as the &#8220;traffic cop&#8221; of the web application.<\/p>\n<p>As far as that &#8220;command line&#8221; PHP usage goes &#8230;<\/p>\n<ul>\n<li>Isn&#8217;t it great to have the one code source for all this?<\/li>\n<li>How are we going to manage this command line usage, out of &#8230;\n<ol>\n<li>interactive in an interactive command line session<\/li>\n<li>set off a background process run of it via the &#8220;&#038;&#8221; suffix<\/li>\n<li>cron<font size=1>tab<\/font> it (on our Linux web server)<\/li>\n<\/ol>\n<p>?<\/li>\n<\/ul>\n<p>Suggestion 1 is kludgy, over the top and awkward to arrange for any long period of time, though useful if non-continuous &#8220;process coverage&#8221; is the go.<\/p>\n<p>Suggestion 2 and 3 are great for &#8220;continuous process coverage&#8221; (we privately think of as &#8220;jigsaw coverage&#8221;), but in our books <font size=2>(and the pamphlettes have scarpered it to <a target=_blank title='?' href='https:\/\/www.google.com\/maps\/search\/pamphlette+island\/@-33.9112506,151.1139931,12z\/data=!3m1!4b1'>Pamphlette Island<\/a><\/font><font size=1> &#8230; which they must intend on &#8220;founding&#8221;?!<\/font><font size=2>)<\/font> cron<font size=1>tab<\/font> is a better option to take for at least two reasons &#8230;<\/p>\n<ul>\n<li>cron<font size=1>tab<\/font> resurrects itself on a system reboot<\/li>\n<li>cron<font size=1>tab<\/font> is self documenting (an important advantage regarding command line processing usage)<\/li>\n<\/ul>\n<p> &#8230; but if we are to use cron<font size=1>tab<\/font> &#8220;jigsaw coverage&#8221;, to avoid &#8220;jigsaw overlap&#8221; we&#8217;re going to have to change &#8230; regarding &#8230;<\/p>\n<blockquote style='width:90%;' cite='https:\/\/stackoverflow.com\/questions\/18919151\/crontab-day-of-the-week-syntax'><p>\n&nbsp;&nbsp;\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 minute (0 &#8211; 59)<br \/>\n&nbsp;&nbsp; \u2502 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 hour (0 &#8211; 23)<br \/>\n&nbsp;&nbsp; \u2502 \u2502 \u250c\u2500\u2500\u2500\u2500\u2500\u2500 day of month (1 &#8211; 31)<br \/>\n&nbsp;&nbsp; \u2502 \u2502 \u2502 \u250c\u2500\u2500\u2500\u2500 month (1 &#8211; 12)<br \/>\n&nbsp;&nbsp; \u2502 \u2502 \u2502 \u2502 \u250c\u2500\u2500 day of week (0 &#8211; 6 => Sunday &#8211; Saturday, or<br \/>\n&nbsp;&nbsp; \u2502 \u2502 \u2502 \u2502 \u2502                1 &#8211; 7 => Monday &#8211; Sunday)<br \/>\n&nbsp;&nbsp; \u2193 \u2193 \u2193 \u2193 \u2193<br \/>\n&nbsp;&nbsp; * * * * * command to be executed\n <\/p><\/blockquote>\n<p> &#8230; thanks to <a target=_blank title='https:\/\/stackoverflow.com\/questions\/18919151\/crontab-day-of-the-week-syntax' href='https:\/\/stackoverflow.com\/questions\/18919151\/crontab-day-of-the-week-syntax'>https:\/\/stackoverflow.com\/questions\/18919151\/crontab-day-of-the-week-syntax<\/a> for above cron<font size=1>tab<\/font> syntax &#8230; as per ( our assumption being that the user will use one of the &#8220;every ? units&#8221; syntax such as <br \/><i>*\/6 * * * * php this_php_happens_every_six_minutes.php<\/i><br \/> ) &#8230;<\/p>\n<table style='width:100%;'>\n<tr>\n<th>To <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php-GETME\" title=\"php_listener.php\">&lt;&#8212;<\/a><\/th>\n<th><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/chat_cron.gif\">&lt;&#8212;<\/a> From<\/th>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<code><br \/>\nif ($argv) {  \/\/ command line ...<br \/>\n    $cfindings=\"\";<br \/>\n    $goes=0;<br \/>\n    $howmanygoes=\"-1\";<br \/>\n    $par=getenv(\"TERM\"); \/\/ thanks to <a target=_blank title='https:\/\/stackoverflow.com\/questions\/3214935\/can-a-bash-script-tell-if-its-being-run-via-cron' href='https:\/\/stackoverflow.com\/questions\/3214935\/can-a-bash-script-tell-if-its-being-run-via-cron'>https:\/\/stackoverflow.com\/questions\/3214935\/can-a-bash-script-tell-if-its-being-run-via-cron<\/a><br \/>\n    if (\"$par\" == \"$TERM\") {  \/\/ via cron<br \/>\n      $cfindings1=exec(\"crontab -l | grep 'php_listener' | grep -v 'grep' | cut -d ' ' -f 1\");<br \/>\n      $cfindings2=exec(\"crontab -l | grep 'php_listener' | grep -v 'grep' | cut -d ' ' -f 2\");<br \/>\n      $cfindings3=exec(\"crontab -l | grep 'php_listener' | grep -v 'grep' | cut -d ' ' -f 3\");<br \/>\n      $cfindings4=exec(\"crontab -l | grep 'php_listener' | grep -v 'grep' | cut -d ' ' -f 4\");<br \/>\n      $cfindings5=exec(\"crontab -l | grep 'php_listener' | grep -v 'grep' | cut -d ' ' -f 5\");<br \/>\n      if (strpos($cfindings1, \"*\/\") !== false) {<br \/>\n        $howmanygoes=12 * explode(\"*\/\", $cfindings1)[1];<br \/>\n      } else if (strpos($cfindings2, \"*\/\") !== false) {<br \/>\n        $howmanygoes=720 * explode(\"*\/\", $cfindings2)[1];<br \/>\n      } else if (strpos($cfindings3, \"*\/\") !== false) {<br \/>\n        $howmanygoes=17280 * explode(\"*\/\", $cfindings3)[1];<br \/>\n      }<br \/>\n    }<br \/>\n    while (1) {<br \/>\n    foreach (glob(\"chat_*.rls\") as $ourfilename) {<br \/>\n      rename($ourfilename, explode(\".rls\", $ourfilename)[0] . \".line\");<br \/>\n    }<br \/>\n    if ($howmanygoes >= 0) { $goes++; if ($goes &gt;= $howmanygoes) {  exit; } }<br \/>\n    sleep(5);<br \/>\n    }<br \/>\n    exit;<br \/>\n}<br \/>\n<\/code>\n<\/td>\n<td style='vertical-align:top;'>\n<code><br \/>\nif ($argv) {  \/\/ command line ...<br \/>\n    while (1) {<br \/>\n    foreach (glob(\"chat_*.rls\") as $ourfilename) {<br \/>\n      rename($ourfilename, explode(\".rls\", $ourfilename)[0] . \".line\");<br \/>\n    }<br \/>\n    sleep(5);<br \/>\n    }<br \/>\n    exit;<br \/>\n}<br \/>\n<\/code>\n<\/td>\n<\/tr>\n<\/table>\n<p>Again, feel free to try <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php-GETME\" title=\"php_listener.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php-GETME\" title=\"php_listener.php\">php_listener.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php\" title=\"Click picture\">chat web application<\/a> &#8220;second draft&#8221;.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/chat-no-sockets-crontab-tutorial\/'>Chat No Sockets Crontab Tutorial<\/a>.<\/p-->\n<hr>\n<p id='cnspt'>Previous relevant <a target=_blank title='Chat No Sockets Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/chat-no-sockets-primer-tutorial\/'>Chat No Sockets Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Chat No Sockets Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/chat_no_sockets.jpg\" title=\"Chat No Sockets Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Chat No Sockets Primer Tutorial<\/p><\/div>\n<p>We&#8217;re starting on a new PHP web application project.  We&#8217;ve got a &#8220;first draft&#8221; of a chat web application that does not use sockets, but rather &#8230;<\/p>\n<ol>\n<li>invites somebody else (via &#8220;Invite&#8221; button) via email or SMS<\/li>\n<li>that &#8220;somebody else&#8221; opens the web application via email or SMS links<\/li>\n<li>from then on keep the chat going via &#8220;Send&#8221; buttons in the two chat incarnations<\/li>\n<\/ol>\n<p>It needs more work, that is for sure, but perhaps you want to see <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php_GETME\" title=\"php_listener.php\">php_listener.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/php_listener.php\" title=\"Click picture\">chat web application<\/a> &#8220;first draft&#8221;.<\/p>\n<p>As with good learning between two parties, each listens, takes it in, and replies, as required.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d50101' onclick='var dv=document.getElementById(\"d50101\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/chat\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d50101' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d50106' onclick='var dv=document.getElementById(\"d50106\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/cron\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d50106' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d50122' onclick='var dv=document.getElementById(\"d50122\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/session\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d50122' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d50127' onclick='var dv=document.getElementById(\"d50127\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/sms\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d50127' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday&#8217;s Chat No Sockets Session Tutorial gives us an opportunity to become more &#8220;granular&#8221; with our examination of nuances to &#8230; the web application&#8217;s &#8220;surfing the web&#8221; look and aesthetics (first look) and usage practicalities (involving button disabling\/enabling at appropriate &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/chat-no-sockets-sms-invitation-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,37],"tags":[2767,126,200,234,272,274,380,707,2114,932,991,997,2024,1159,1319,1402],"class_list":["post-50127","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-_session","tag-background","tag-chat","tag-command-line","tag-cron","tag-crontab","tag-email","tag-linux","tag-listener","tag-php","tag-process","tag-programming","tag-session","tag-sms","tag-tutorial","tag-web-application"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50127"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=50127"}],"version-history":[{"count":6,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50127\/revisions"}],"predecessor-version":[{"id":50133,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/50127\/revisions\/50133"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=50127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=50127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=50127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}