PHP vs JS:为什么PHP操作基本上是同步执行而JS操作不是?

If we look into the way PHP and JS frameworks are written you can see a great difference. JavaScript generally has callbacks/promises for operations that might take an undetermined amount of time. Even though PHP has the possibility to pass functions as a parameter, it's not commonly used.

I'd like to take database operations as an example to state my case:

PHP's Eloquent:

$organization = Organization::where('name', '=', 'test')->first();

Node.JS Sequelize:

Organization.findOne({where: {name: 'test'}})
    .then(function (organization) {
            // Organization has been fetched here
        }
    );

As you can see Sequelize uses promises to make the operation async. However, PHP's Eloquent does not.

Apart from framework benchmarks, does this mean the Node.JS is faster/more efficient since it is not blocking? Or is this rather because JS is single-threaded? Maybe I have a wrong perception and is the pattern equally implemented in both languages?

It's possible to write blocking node.js code, and it's possible to write asynchronous PHP code (see the libevent extension, the amphp project or the ReactPHP project). Neither is really idiomatic. This means it's atypical and perhaps not recommended except for specialized use-cases.

PHP can work synchronously because in a typical webserver there are many PHP process running at the same time. Each handling 1 HTTP request at a time.

There are pros and cons to each model. For example, it's harder to do multiple things in node.js if you're doing CPU-bound work, and in PHP you might need more memory usage for higher concurrency, because often you might be waiting on IO in PHP, so most of your PHP processes might end up waiting. So your CPU usage ends up being low, and you have a lot of PHP process waiting around for IO while all of them have a copy of your favourite web framework in memory.

Node.js allows for building some types of applications that are harder to do in PHP because there's no shared memory space. But then again, that advantage might end up being less relevant once your node.js application needs to grow beyond a single process.

Anyway, it's an extremely broad question. In some ways both node.js and PHP can address similar use-cases, but when your use-cases become more exotic one of the two might be better.

If you're mostly a building a web application, you're not expecting massive scale, it probably doesn't really matter that much what you go for.

So ultimately which is the better choice depends on your use-case.