D
D
DTX2017-01-25 14:25:06
PHP
DTX, 2017-01-25 14:25:06

How can I make php not wait for the previous thread to finish?

There is a page:

echo 'Start: '.date('c');
    echo '<br/>';
    sleep(5);
    echo 'End: '.date('c');

If you open two such pages, then the second will wait for the completion of the first.
uW2Nr8S.png
How to make a second php thread run?
Thread safe/Non thread safe - isn't that what I need by any chance?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
D
DTX, 2017-01-30
@DirecTwiX

The problem was in xdebug. Everything is fine without him.
I set it up like this:
https://habrahabr.ru/post/250323/
Well, in chrome, you need to set the "Disable cache" flag using DevTools

E
Eugene Volf, 2017-01-25
@Wolfnsex

For example, so .

A
Andrey Burov, 2017-01-25
@BuriK666

You may have php sessions there. session_write_close will help
. UPD: If you use the built-in PHP server , then no way. It processes only one request at a time.

A
Alexander Kubintsev, 2017-01-25
@akubintsev

You seem to be using PHP's built-in web server. It works in 1 thread. Therefore, blocking it through sleep () other requests are waiting.

P
Philipp, 2017-01-25
@zoonman

This will help you, but will only work with Nginx + PHP-FPM.

// здесь весь вывод клиенту
session_write_close ();
fastcgi_finish_request();

// здесь делать долгую работу (отправлять письмо или другое)

K
Konstantin Sazhenov, 2017-08-22
@sakost

Try to integrate this python script into your C++

import requests

class API:
    API_URL = 'https://api.vk.com/method/'
    def __init___(self, image_path, access_token):
        self.img = image_path
        self.token = access_token
    def send(self):
        response = requests.post(self.API_URL + 'photos.getMessagesUploadServer', params={'access_token': self.token}).json()
        req = requests.post(response['upload_url'], params={'access_token': self.token}, files={'file': open(self.img, 'rb')}).json()
        req.update({'access_token': self.token})
        req = requests.post(self.API_URL + 'photos.saveMessagesPhoto', params=req)
        return req.json()
# Usage :
# api = API('img.jpeg', 'XXX')
# response = api.send()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question