Promise in PHP asynchronously?

I can not understand, a Promise help you cope with the hell of Albekov in asynchronous operations, but PHP is not executed asynchronously (unlike JS)
1. what problems are solved Promise in PHP? (guzzle/promises, reactphp/promise)
2. Is it possible to perform operations asynchronously\parallel in PHP using promises? (the implementation of reactphp/promise and guzzle/promises - no asynchronisity and paralleli)
July 2nd 19 at 18:01
1 answer
July 2nd 19 at 18:03
why do you think that php is not running?

1. make the code asynchronous
2. the parallelism is not async.
PHP can be asynchronous, but you need to use
and. Thread, or
b. pcntl_fork, or
V. to turn up kurumi the queries yourself

1. what kind of async going on, if I can do a heavy query (or just put a sleep(10)) and all will be waiting for him, because none of the libraries (guzzle/promises, reactphp/promise) does not implement any Thread or pcntl_fork.

2. possible. the difference here is very subtle, probably async this is a special case of paralleli (tasks can be processed in parallel and synchronously, and can be in parallel and asynchronously). But asynchrony implies parallel execution - this means the non-blocking tasks to each other, in JS it is out of the box (or they emulate it well) PHP, I can't imagine asynchronous\parallel. - aaliyah commented on July 2nd 19 at 18:06
and you are confusing async with multithreading?
what are the events that need to wait:
- answer base
- receiving the data in the stream
more in PHP there are no such things that can not wait

1. you can do a heavy query and not wait for a response. using mysqli and poll. PHP was not initially sharpened by the events, which is implemented async.

I don't think you quite understand how it works async in js and how it behaves inside. what is the locking blocks, etc.
In js, unlike PHP, executed with just one thread for everything (!) connection. In PHP, for each link of your thread (roughly speaking) and it makes no sense to switch to another context.

2. Asynchrony is the way in which the waiting time spent on tasks from the stack of the task, but when the event occurs, the current task is interrupted and the flow returns to the previous one, which stood waiting. Working js. It seems to be asynchronous, but the task is still executed by a single thread, which means one after another, not concurrently. In PHP you can make trosow asynchronous parallel execution of tasks, as you said am using pthread, epoll and fork.
In PHP, Yes, harder to implement, because it is not native, but it is moving, though very slowly (I'm talking about the emergence of pthread and poll is to native instruments for parallelism and asynchrony). - mina50 commented on July 2nd 19 at 18:09
:
1. in one request - PHP single-threaded and asynchronous, hence the question: why single-threaded PHP (within one request) Promise?
mysqli and poll do not decide anything, because there is the postgres of perezii with files and a lot of things in PHP is blocking the flow of the function. - aaliyah commented on July 2nd 19 at 18:12
: how not to decide. You can either feed handler to poll and do something else, but it's not enough when you need to.
Promise in PHP is used to branch your logic. Implementation, so to say state-machine.
But in js promises are only needed where you have a bunch of unrelated events (whatever the interface). And in the case of js backend, the same garbage comes out. You still need to wait for a response database, for example.
With prosimii you can still prepare a template and then after a positive decision to do the insert. A small savings.
Sometimes it's just mainstream, sometimes a necessity. Depends on the solutions used within the site. - mina50 commented on July 2nd 19 at 18:15

Find more questions by tags PHP