アプリ関連ニュース

Websockets and Server Sent Events

Today, I would like to share about WebSockets and Server Sent Event (SSE). Both WebSockets and Server Sent Events are realtime push-based communication methods. Let’s explore at them.

WebSockets

WebSockets is a technology that enables bidirectional real-time interactive communication between a client and a server. WebSockets use the WebSocket protocol for communication.

Advantages

– WebSockets allow realtime bidirectional communication.

– WebSockets are supported in most of the latest browsers today.

– WebSockets don’t use XMLHttpRequest. So unnecessary data loads to the server are reduced.

– Binary data and UTF-8 text formats can be sent with WebSockets.

Disadvantages

WebSockets need TCP connection to work and don’t entirely need HTTP. They just need HTTP to initiate the connection for establishing standalone TCP connection that is used with WebSocket protocol. So some of HTTP functionality cannot be taken in WebSockets. The following are disadvantages of Websockets.

– No compression support

– Not support HTTP/2 mutiplexing

– WebSockets are not supported in old version browsers

– Setting up WebSockets is not simple and takes some time.

– May be issues for some firewalls with packet monitoring

Server Sent Events

SSE (Server-Sent Events) is a technology that allows a client browser to receive automatic updates from a server over a standard HTTP connection but not bidirectional. SSE use the JavaScript EventSource API.

Advantages

– Since SSE uses HTTP, it takes some advantages of HTTP functionality.

– SSE is easy to use and faster to setup.

– SSE will not cause problems with packet monitoring.

Disadvantages

– SSE does not allow bidirectional communication or data transmission.

– SSE can only send UTF-8 data and not binary data.

– SSE has restrictions about maximum number of open conenctions.

These are advantages and disadvantages of WebSockets and Server Sent Event. The case of choosing one of them depends on which solutions you want to solve and what your system needs.

This is all for now. Hope you enjoy that.

By Asahi



Introduction to Cloudflare

Cloudflare is one of the world’s largest networks. Today, businesses, nonprofits, bloggers, and anyone with an online presence can benefit from faster, more secure websites with the help of Cloudflare.

There are millions of internet properties on Cloudflare and the network is growing by tens of thousands every day. Cloudflare powers internet requests for millions of websites, serving an average of 36 million HTTP requests per second.

Cloudflare network map
Credit: Cloudflare

In the early days of the Internet, when you wanted to load a website, your computer sent a request to a server, and the server returned the requested web page.

If the server is receiving too many requests at once, its servers could be overwhelmed and crash, stalling anyone trying to access the resources they host.

This made it difficult for the owners to provide fast, secure, and reliable content. Cloudflare was created to help mitigate these issues and provide users with resources to keep their sites, apps, and blogs safe and efficient. This is done using a powerful perimeter network that delivers content and other services as close as possible so you can access information as quickly as possible.

Cloudflare also provides security by protecting Internet properties from malicious activity such as DDoS attacks, malicious bots, and other malicious intrusions. It also offers rich features like his SSL and content delivery to all websites in its network.

Also, the website owner can easily embed the app into her website without being a developer.

If you’re a developer, you can run your Javascript code in a powerful perimeter network, keeping you as close to your users as possible. This eliminates latency and improves user experience.

Yuuma



Laravel Tips

一度に1つのレコードをseedingすると、DBが遅くなる可能性があります。より良い方法は、PHPでレコードを大量に作成し、それをChunkしてシードするで1万queryから5queryにする方法
use App\Models\User;

User::factory(10000)->create();

上記のコードを見ると、Laravelは1ユーザーを作成し、1queryでデータベースに挿入しています。これを1万回繰り返しています。そうすると、パフォーマンスにとって悪いことで、DBを遅くしてしまいます。しかし、これを簡単に解決することができます!

$records = User::factory()->count(10000)->make();

$records->chunk(2000)->each(function($chunk) {
     User::insert($chunk->toArray());
});

上のコードでは、メモリ(PHP)上に10,000のユーザーレコードが作成されています。 次に、これを2,000レコードのチャンクに分割して配列に変換し、クエリの数を10,000から5つにします!

ということで、今回はこれで終わります。

金曜担当 – Ami



Introduction to NFT

NFT stands for Non-Fungible Tokens (NFT) and are typically created using the same kind of programming used for cryptocurrencies. Simply put, these crypto assets are based on blockchain technology. It cannot be exchanged or traded in a comparable manner with other crypto assets.

Like Bitcoin and Ethereum. The term NFT clearly expresses that it has unique properties and cannot be replaced or exchanged. Physical currency and cryptocurrency are interchangeable. That is, they can be traded or exchanged with each other.

What Is an NFT?
Image Credit : VOA

Most NFTs reside on the Ethereum cryptocurrency blockchain, a distributed public ledger that records transactions and they are individual tokens that store valuable information. They can be bought and sold like any other kind of physical art, as it has a value set largely by the market and demand. Proprietary NFT data facilitates verification and validation of ownership and transfer of tokens between holders.

Blockchain technology and NFTs offer artists and content creators a unique opportunity to monetize their products. For example, artists no longer have to rely on galleries and auction houses to sell their art. Alternatively, the artist can sell it directly to consumers as an NFT. This also allows consumers to keep most of their profits. Additionally, artists can schedule royalties to receive a portion of the sale each time their art is sold to a new owner. This is an attractive feature. This is because artists typically do not receive future earnings after their art is first sold.

Art isn’t the only way to make money with NFTs. Brands such as Charmin and Taco Bell are auctioning NFT-themed art to raise money for charity.

Even celebrities like Snoop Dogg and Lindsay Lohan have jumped on the NFT bandwagon, releasing memorabilia, artwork, and unique moments as securitized NFTs.

Let me finish this article as it’s getting long. I still want to talk about this in near future.

Yuuma.



Custom Node JS logger class with Winston package

Today I would like to share a custom Node JS logger Class using winston package. Let’s take a look.

const winston = require('winston')
nowDate = () => {return new Date(Date.now()).toUTCString()}

class CustomLogger {
  constructor() {
    
    this.logData = null
    const logger = winston.createLogger({
      transports: [
        new winston.transports.Console(),
        new winston.transports.File({
          filename: `./logs/debug.log`
        })
      ],
      format: winston.format.printf((info) => {
        let message = `${nowDate()} | ${info.level.toUpperCase()} | debug.log | ${info.message} | `
        message = info.data ? message + `data:${JSON.stringify(info.data)} | ` : message
        message = this.logData ? message + `logData:${JSON.stringify(this.logData)} | ` : message
        return message
      })
   });
   this.logger = logger
}
setLogData(logData) {
  this.logData = logData
}
async info(message) {
  this.logger.log('info', message);
}
async info(message, data) {
  this.logger.log('info', message, {
    data
  })
}
async debug(message) {
  this.logger.log('debug', message);
}
async debug(message, data) {
  this.logger.log('debug', message, {
    data
  })
}
async error(message) {
  this.logger.log('error', message);
}
async error(message, data) {
  this.logger.log('error', message, {
    data
  })
}
}
module.exports = CustomLogger

The logger class is as above. It is very simple to use. Just call the class and instantiate the class as follows.

const Logger = require('./customLogger')
const logger = new Logger()

This is all for now. Hope you enjoy that.

By Asahi



アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム