PHP extension with thread

General discussion on PHP
Post Reply
simo4761
Posts: 1
Joined: Fri Dec 02, 2016 9:41 am

PHP extension with thread

Post by simo4761 » Fri Dec 02, 2016 9:50 am

Hi all,

I do not know if I am in the good section. I developpe an extension php, and I would like I could use Linux pthread in my extension.
But I have a feeling that my thread do not work, I looked for the documentation on the Internet but I find no concrete example.
Must to use thread zts be activated? Here is my code :

Code: Select all

void *called_from_thread(void *num){
    php_printf(" print by thread");
}

PHP_FUNCTION(test){
    pthread_t inc_x_thread;
    int x = 0;

    if(pthread_create(&inc_x_thread, NULL, called_from_thread, &x)) {
        php_printf("Error creating thread");
        return;
    }

    php_printf("This is main print");

    if(pthread_join(inc_x_thread, NULL)) {
        php_printf("Error joining thread");
        return;
    }
}
When I execute my extension in php, I always obtain the same display, This is main print print by thread For me the normal behavior of thread would be to have displays different during refreshment of page.

Every help is welcome :)

Simon

User avatar
zvika
Zend Global Support
Posts: 997
Joined: Sun Dec 14, 2008 9:48 am
Contact:

Re: PHP extension with thread

Post by zvika » Sun Dec 04, 2016 11:02 am

Simon,
I'm not sure what exposure you will get here with PHP extension devs.
Try a PHP internals mailing list, this is a PHP language development board.
Good luck!
Zvika Dror
Zend Support Team

Post Reply