jueves, 28 de enero de 2021

Synchronous vs. Asynchronous

 

Synchronous vs. Asynchronous

Definition:

  • Synchronous communication: The calling party requests a service, and waits for the service to complete. Only when it receives the result of the service it continues with its work. A timeout may be defined, so that if the service does not finish within the defined period the call is assumed to have failed and the caller continues.

  • Asynchronous communication: The calling party initiates a service call, but does not wait for the result. The caller immediately continues with its work without caring for the result. If the caller is interested in the result there are mechanisms which we'll discuss in the next paragraphs.

Be aware that the distinction between synchronous and asynchronous is highly dependent on the viewpoint. Often asynchronous is used in the sense of “the user interface must stay responsive all the time”. This interpretation often leads to the wrong conclusion: “…and therefore every communication must be asynchronous”. A non-blocking GUI usually has nothing to do with the low-level communication contracts and can be achieved by different means, e.g. parallel processing of the interactive and communication tasks. The truth is that synchronous communication on a certain level of abstraction can be implemented with asynchronous interfaces on another level of abstraction and vice versa, if needed.

File based communication is often considered to be asynchronous. One party writes a file but does not care if the other party is active, fetches the file or is able to process it. However it is possible to implement another layer of functionality so that the second (reading) party gives feedback, e.g. by writing a short result file, so that the first (writing) party can wait and poll for the result of the file processing. This layer introduces a synchronous communication over file exchange.

Communication over a database often is implemented by one party writing execution orders into a special table and the other party reads this table periodically and processes new entries, marking them as “done” or “failed” after execution. So far this is an asynchronous communication pattern. As soon as the first party waits for the result of the execution, this second layer introduces a synchronous communication pattern again.

https://docs.plm.automation.siemens.com/content/pl4x/18.1/T4EA/en_US/Teamcenter_Gateway-Technical_Connectivity_Guide/synchronous_vs_asynchronous.html

jueves, 24 de diciembre de 2020

setting time zone php

 <?php

date_default_timezone_set("Asia/Bangkok");
echo date_default_timezone_get();
echo "<br>";
echo time();

echo "<br>";
echo date('r');
?>

miércoles, 18 de noviembre de 2020

Remove newlines using regex.

 //Replace the newline and carriage return characters

//using regex and preg_replace.

$text = preg_replace("/\r|\n/", "", $text);


remove \r\n 

viernes, 23 de octubre de 2020

php crud

 

https://www.studentstutorial.com/php/php-crud

https://drive.google.com/file/d/14579xTbSKyI3ZSJHfMSRSPBwpN8oJooC/view?usp=sharing

miércoles, 7 de octubre de 2020

google speech library

 require google/cloud-speech


https://cloud.google.com/speech-to-text/docs/quickstart-client-libraries#client-libraries-install-php

Send JSON data via POST with PHP cURL

 

The following example makes an HTTP POST request and send the JSON data to URL with cURL in PHP.

  • Specify the URL ($url) where the JSON data need to be sent.
  • Initiate new cURL resource using curl_init().
  • Setup data in PHP array and encode into a JSON string using json_encode().
  • Attach JSON data to the POST fields using the CURLOPT_POSTFIELDS option.
  • Set the Content-Type of request to application/json using the CURLOPT_HTTPHEADER option.
  • Return response as a string instead of outputting it using the CURLOPT_RETURNTRANSFER option.
  • Finally, the curl_exec() function is used to execute the POST request.
// API URL
$url 'http://www.example.com/api';

// Create a new cURL resource
$ch curl_init($url);

// Setup request to send json via POST
$data = array(
    
'username' => 'codexworld',
    
'password' => '123456'
);
$payload json_encode(array("user" => $data));

// Attach encoded JSON string to the POST fields
curl_setopt($chCURLOPT_POSTFIELDS$payload);

// Set the content type to application/json
curl_setopt($chCURLOPT_HTTPHEADER, array('Content-Type:application/json'));

// Return response instead of outputting
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

// Execute the POST request
$result curl_exec($ch);

// Close cURL resource
curl_close($ch);

Receive JSON POST Data using PHP

The following example shows how you can get or fetch the JSON POST data using PHP.

  • Use json_decode() function to decoded JSON data in PHP.
  • The file_get_contents() function is used to received data in a more readable format.
$data json_decode(file_get_contents('php://input'), true);

miércoles, 30 de septiembre de 2020

php postgre

 install dependencies  sudo apt-get install php7.0-pgsql

yum install php-pgsql

restart apache

https://stackoverflow.com/questions/38981799/unable-to-install-php5-pgsql-on-ubuntu-16-04/42772824


<?php

   $host        = "host = hus-west-2.rds.amazonaws.com";

   $port        = "port = 5432";

   $dbname      = "dbname = product";

    $pass="dElm0zL";

$pid=$argv[1];

    $credentials = "user=phone  password=$pass";


   $db = pg_connect( "$host $port $dbname $credentials"  );

   if(!$db) {

      echo "Error : Unable to open database\n";

   } else {

      echo "Opened database successfully\n";

   }


   $sql =<<<EOF

      SELECT * FROM public.howardmillerinventory where "Clock"='$pid'

EOF;


   $ret = pg_query($db, $sql);

   if(!$ret) {

      echo pg_last_error($db);

      exit;

   }

   while($row = pg_fetch_row($ret)) {

      echo "Item# = ". $row[0] . "\n";

      echo "Stock= ". $row[1] ."\n";

      }

   echo "Operation done successfully\n";

   pg_close($db);

?>