Still now I’ve found Xdebug as the most useful tool to profile the bottleneck of an API. To understand the profiling result step by step- there is Webgrind.
To install Xdebug-
There are situations when we need to migrate data from one database to another. For example, I’d some unit tests for which I need to use SQLite with minimal data set replicated from production DB. Loading fixtures was not that easy option due to some chained interdependent calls.
There are situations when we need to make our one-process task into a multi-process task so that we can take advantage of the operating system’s multitasking capabilities.
The basic conceptual difference between multiprocessing and multithreading– A process, is a unique instance of a program with its own memory space, own process ID number etc. Whereas, a thread can be thought of as a virtual process, it does not have its own process ID, does not have its own memory space, but is still able to take advantage of multitasking.
Without thread, parallelism is incomplete. Multithreading in PHP with pthreads:
From PHP DOC–
pthreads is an Object Orientated API that allows user-land multi-threading in PHP. It includes all the tools you need to create multi-threaded applications targeted at the Web or the Console. PHP applications can create, read, write, execute and synchronize with Threads, Workers and Threaded objects.
The issue is with this is a PECL extension. Not bundled in PHP library by default yet.
pthreads releases are hosted by PECL and the source code by » github, the easiest route to installation is the normal PECL route.
So now the question is there any minimal alternative to achieve the goal?
Yes, this post is about the most basic concept that using
if/ else should be avoided within loop as much as possible. Optimizing code is always important and when it’s about performance then the basic efficiency rules should be followed at first. Practically there are many situations when a loop iterates over large data set e.g. 1m; there may be different required computation in the same loop- but if possible the loop should maintain branch prediction; avoid unnecessary
Following simple rules lead to performance advantage certainly. Branch prediction is a simple concept to optimize a loop-
I got this question in an interview. Was aware of this conception and explained properly. But I think this topic is worth to explain, so that’s why this post is-
Shallow copy– In the process of shallow copying A, B will copy all of A’s field values. If the field value is a memory address it copies the memory address, and if the field value is a primitive type it copies the value of the primitive type. In layman’s term shallow copy duplicates as minimum as possible. But the disadvantage is if you modify the memory address that one of B’s fields point to, you are also modifying what A’s fields point to.
Deep copy– In this process the data is actually copied completely. The advantage is that A and B do not depend on each other but this process is relatively slower and more expensive.