Skip to main content

Reverse proxy server

Comments

Popular posts from this blog

PHP json_encode return empty array [] instead of empty object {}

Problem: Get below array for example.  $status = array ( "message" => "error" , "club_id" => $_club_id , "status" => "1" , "membership_info" => array (), ); This array will be encoded in json format echo json_encode($status); This function return json: {"message":"error","club_id":275,"status":"1","membership_info": [] } Notice the empty array [], it is not consistent, it should be an empty object {} {"message":"error","club_id":275,"status":"1","membership_info": {} } The cause: This problem is caused by the called function array(), which yields an empty array [] Solution: There are 2 solutions for this issue: Solution 1: Call new stdClass instead of array(), stdClass generates an empty object {} Solution 2: The above solution is complex in case there are plenty of arr...

Calculate the execution time of multi-thread program

Indeed, multiple-thread program helps improve the performance of the application. One of the best ways to test if the performance is really improved is the execution time. In Java,  System.currentTimeMillis();  is usually used to calculate the execution time of a code block. long startTime = System.currentTimeMillis(); <code block here> long stopTime = System.currentTimeMillis(); long elapsedTime = stopTime - startTime; But if the code block contains multiple threads inside then this calculation is not true. Usually, the elapsedTime will be calculated before the longest thread completed, as a result, the elapsedTime will be incorrectly calculated. To cope with this problem, CountDownLatch is a simple tool to be used. The general idea is that this object will set a countdown number, called stopWatch , equal to the number of threads. In run() function of each thread, stopLatch is coutdowned. Outside of the code block, stopWatch calls await function, which m...