Tag Archives: developer

Understanding Web Acceleration

web acceleration

Usually, a high traffic website must support hundreds of thousands or millions of users. Not to mention the demand of user for a fast and reliable website. Therefore, to meet such high volumes, some web developers prefer to add more server hardware.

However, this method can be expensive. So, in order to reduce your operational cost, you can use web acceleration as another option. Web acceleration produces better speed delivery of both static and dynamic content. Furthermore, it will enable your web servers to handle more client request without the need for more hardware.

In general, web acceleration is a content delivery network. It aims to speed up the transfer of content between web servers and client browsers by utilizing a variety of techniques such as caching and compression.

HTTP Optimization
Load balancer or reverse proxy server is one of the primary ways to accelerate web traffic as it flows between clients and backend servers. However, this can create inefficiencies in server utilization and cause poor performance for other users as well.

In HTTP optimization techniques, the load balancer is in between clients and servers. It forwards requests for content to backend servers in a streamlined and efficient way. Therefore, this method maximizes speed and server utilization.

Caching and Prefetching
Rather than fetching it over and over from back end servers, web acceleration server cache or locally store commonly requested information. This will avoid any wasted server resources and increase the speed of content delivery. In fact, to prevent serving content that is out of date, the web accelerator will refresh cached content at a specified interval.

Furthermore, the web accelerator is also able to prefetch and cache content that the user is likely to ask for, such as the next page of a document. This method will enable web accelerator to deliver the content immediately after the user requests it.

Compression
To reduce transfer times, a web accelerator will compress large files, such as image or video files.

SSL/TLS Processing
In order to serve content faster, some advanced web accelerators can offload computationally intensive processing from backend servers. For example, encryption and decryption of documents during transmissions secured with Secure Sockets Layer (SSL) or Transport Layer Security (TLS).

 

How to Synchronize WordPress Live and Development Databases

How-to-Synchronize-WordPress-Live-and-Development-Databases

As a web developer, using real content is considerably easier when developing WordPress themes. However, in the process you will encounter some unexpected situations, especially when adding pages, posts, media and comments. Hence, the only way to improve your workflow is by automatically synchronizing your content.

Synchronization Snags

You may think that database replication can be more challenging than you expect. But, you can learn from several reasons why few coders can survive in this dreamland.

Data Differences

There are various configuration settings in WordPress database. Some of them are the domain name and paths which are used throughout posts and asset references. To avoid any undesired consequences, do not import this information into a local database. Even though, the image and link URLs seems like working but it could take you back to the live server. To add to the complications, WordPress serializes some data. It can be difficult to parse and change those values.

Multiple Installations

If you are working alone on a local installation and uploading to a single live server, synchronization becomes less necessary and complicated compare to working with teams with multiple developers, staging servers, or more than one production server.

Databases can be Large

You’re unlikely to want or need numerous megabytes of post data, even if fast incremental synchronization were implemented.

It’s Not Just Databases

In the local file system, WordPress stores uploaded images and other media. Those need to be downloaded and the database references must be updated accordingly. Besides, you also need to make sure that theme and plugin files are synchronized, enabled, and configured appropriately. This will help avoiding certain plugins, e.g. multi-site, caching, etc enabled.

Is Synchronization Possible?

It will be difficult to find one option that can fit to all sizes as it will depend on your circumstances. For instance, you may want one-way replication from live to development servers. However, you can choose one among so many options below:

WP Migrate DB Pro

Many people find that the WP Migrate Pro WordPress plugin is the best-known and easiest choice from Delicious Brains. It is available in a free edition.

WP Sync DB

WP Sync DB is an open-source fork of WP Migrate DB.

VersionPress

VersionPress is able to manage database merging. It is a Git-based version control plugin for WordPress. This product seems promising even though it is in development process.

WPSiteSync for Content

WPSiteSync permits real-time synchronization of pages, posts and other data. It is also offering free and commercial editions.

Database Sync

Even though, Database Sync is not compatible with multi-site installations but it may be enough for some developers.

WordPress Importer

WordPress Importer is suitable for those who prefer a safer, more manual process, exports posts, pages, comments, categories, tags, authors and other data to an XML file that can be imported into another installation.

SyncDB

SyncDB is a bash script. It synchronizes local and remote WordPress databases.

WP Staging

The WordPress WP Staging plugin can clone data and files from live to development or staging servers.

WordPress GitHub Sync

The WordPress GitHub Sync plugin allows you to synchronize content allows you synchronize content from a GitHub repository or Jekyll-created website.

The Activity Lifecycle of Android

The-Activity-Lifecycle-of-Android_1

In Android activity lifecycle, there are four activities that permit the activity to know a state has changed. They include creating, stopping or resuming an activity or destroying the process in which the activity resides.

Through activity lifecycle concept, web developers and android developers can learn to understand how your activity works properly when the user leaves and re-enters the activity. This means each callback permits you to perform specific work that’s appropriate to a given change of state. Doing the right work at the right time and handling transitions properly make your app more robust and performant. By having good implementation of the lifecycle callbacks will ensure your app keeps away from several things bellows:

  • Consuming valuable system resources when the user is not actively using it.
  • Crashing or losing the user’s progress when the screen rotates between landscape and portrait orientation.
  • Losing the user’s progress if they leave your app and return to it at a later time.
  • Crashing if the user receives a phone call or switches to another app while using your app.

In the next section, we will discuss the lifecycle paradigm and then we will explain each of the callbacks.

Activity-Lifecycle Concepts

The Activity class offers a core set of six callbacks to navigate transitions between stages of the activity lifecycle, such as: onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy(). The system navigates each of these callbacks as an activity enters a new state.

Figure 1 presents a visual representation of this paradigm.

diagram

diagram

The chart above shows the activity states, the activity will be more complex depends on your requests. If you only implement a simple activity state, you don’t need to implement all the lifecycle methods. But, you still need to understand all of the lifecycle and implement those that ensure your app runs the way users want.

Lifecycle Callbacks

This section provides conceptual and implementation information about the callback methods used during the activity lifecycle.

onCreate()

This callback is the first stage when the system first creates the activity. The activity enters the created state. You perform basic application startup logic that happens only once for the entire life of the activity, in the onCreate()method. For example, your implementation of onCreate()might bind the data to lists, initialize background threads, and instantiate some class-scope variables. This method receives the parameter savedInstanceState, which is a Bundle object containing the activity’s previously saved state. The value of the object is null, if the activity has never existed before.

To understand fundamental setup for the activity, such as declaring the user interface, defining member variables, and configuring some of the UI. In this example, by passing file’s resource ID R.layout.main_activity to setContentView().

TextView mTextView;

// some transient state for the activity instance
String mGameState;

@Override
public void onCreate(Bundle savedInstanceState) {
    // call the super class onCreate to complete the creation of activity like
    // the view hierarchy
    super.onCreate(savedInstanceState);

    // recovering the instance state
    if (savedInstanceState != null) {
        mGameState = savedInstanceState.getString(GAME_STATE_KEY);
    }

    // set the user interface layout for this Activity
    // the layout file is defined in the project res/layout/main_activity.xml file
    setContentView(R.layout.main_activity);

    // initialize member TextView so we can manipulate it later
    mTextView = (TextView) findViewById(R.id.text_view);
}

// This callback is called only when there is a saved instance previously saved using
// onSaveInstanceState(). We restore some state in onCreate() while we can optionally restore
// other state here, possibly usable after onStart() has completed.
// The savedInstanceState Bundle is same as the one used in onCreate().
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    mTextView.setText(savedInstanceState.getString(TEXT_VIEW_KEY));
}

// invoked when the activity may be temporarily destroyed, save the instance state here
@Override
public void onSaveInstanceState(Bundle outState) {
    out.putString(GAME_STATE_KEY, mGameState);
    out.putString(TEXT_VIEW_KEY, mTextView.getText());

    // call superclass to save any view hierarchy
    super.onSaveInstanceState(out);

You can create new objects in your activity code and build a view hierarchy by inserting new Views into a ViewGroup. You then use that layout by passing the root ViewGroup to setContentView(). To get further information about creating a user interface, you can see the User Interface documentation.

Your activity does not reside in the Created state. The activity enters the Started State, after the onCreate() method finishes execution. Then, the system calls the onStart() and onResume() methods in quick succession. The next section explains the onStart()callback.

  • onStart()

The system demands this callback, when the activity enters the Started state. In order to make the activity visible to the user, you can use the onStart()call as the app prepares for the activity to enter the foreground and become interactive.

Besides, it also registers a BroadcastReceiver that monitors changes that are reflected in the UI. The activity does not stay resident in the Started state, the onStart() method completes very quickly and, as with the Created state. The activity will enter the Resumed state, once this callback finishes, and the system invokes the onResume()method.

  • onResume()

The onResume() system invokes the callback, when the activity enters the Resumed state. The system will once again calls as onResume() method, if the activity returns to the Resumed state from the Paused state. For this reason, to initialize components that you release during onPause(), you should implement onResume(). For example, you may initializa the camera as follows:

@Override
public void onResume() {
    super.onResume();  // Always call the superclass method first

    // Get the Camera instance as the activity achieves full user focus
    if (mCamera == null) {
        initializeCamera(); // Local method to handle camera init
    }

Furthermore, to initialize components that you release during onPause(), you should implement onResume(). Then, perform any other initializations that must occur each time the activity enters the Resumed state.

  • onPause()

To pause operations such animations and music playback that should not continue while the Activity is in the Paused state, and that you expect to resume shortly. There are several reasons why an activity may end up in this state:

  • A new, semi-transparent activity (such as a dialog) opens. As long as the activity is still     partially visible but not in focus, it remains paused.
  • Some event interrupts app execution, as described in the onResume() This is the most common case.
  • In Android 7.0 (API level 24) or higher, multiple apps run in multi-window mode. Because only one of the apps (windows) has focus at any time, the system pauses all of the other apps.

For example, the onPause()method is a good place to release it, if your application uses the camera. The following example of onPause() is the same to the  onResume() example above, releasing the camera that the  onResume() example initialized.

@Override
public void onPause() {
    super.onPause();  // Always call the superclass method first

    // Release the Camera because we don’t need it when paused
    // and other activities might need to use it.
    if (mCamera != null) {
        mCamera.release();
        mCamera = null;
    }
}

  • onStop()

The Stopped state is when your activity is no longer visible to the user and the system invokes the onStop()callback. You can also call your activity as onStop() when the activity has finished running, and is about to be terminated. Below is how an implementation of onStop() that saves the contents of a draft note to persistent storage:

@Override
protected void onStop() {
    // call the superclass method first
    super.onStop();

    // save the note’s current draft, because the activity is stopping
    // and we want to be sure the current note progress isn’t lost.
    ContentValues values = new ContentValues();
    values.put(NotePad.Notes.COLUMN_NAME_NOTE, getCurrentNoteText());
    values.put(NotePad.Notes.COLUMN_NAME_TITLE, getCurrentNoteTitle());

    // do this update in background on an AsyncQueryHandler or equivalent
    mAsyncQueryHandler.startUpdate (
            mToken,  // int token to correlate calls
            null,    // cookie, not used here
            mUri,    // The URI for the note to update.
            values,  // The map of column names and new values to apply to them.
            null,    // No SELECT criteria are used.
            null     // No WHERE columns are used.
    );
}

  • OnDestroy()

This is the final call that the activity receives. Usually this activity exists due to someone’s calling  finish(), or because the system is temporarily destroying the process containing the activity to save space.

The system may also call this method when an orientation change occurs, and then immediately call onCreate() to recreate the process in the new orientation.

 Activity State and Ejection from Memory

Instead the system kills an activity directly; it kills the process in which the activity runs, destroying not only the activity but also everything else running in the process, as well. Basically, when it needs to free up the RAM, the system will kill process. Moreover, a user can also kill a process by using the Application Manager under Settings to kill the corresponding app.

Table 1 shows the correlation among process state, activity state, and likelihood of the system’s killing

Likelihood of being killed Process state Activity state
Least Foreground (having or about to get focus) Created
Started
Resumed
More Background (lost focus) Paused
Most Background (not visible) Stopped
Empty Destroyed