We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

phthreads

Hello Community,

My application requires me to get max speed out of every request cycle.

It will make multiple API requests and then process those response as soon as they come in.

I have decided to try Phalcon (my first experience with it) and also use pthreads for parallel API requet cycles.

When I try simple threading scripts they work.

But once I make those calls from Phalcon I get erros related to missing Thread components.

If anyone has any experience with Phalcon and pthreads please let me know and I will share my code in detail what works and what does not.

I can share the following to begin with:

$ php -i | grep -i thread

Configure Command => './configure' '--prefix=/etc/php7' '--with-bz2' '--with-zlib' '--enable-zip' '--disable-cgi' '--enable-soap' '--enable-intl' '--with-openssl' '--with-readline' '--with-curl' '--enable-ftp' '--enable-mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--enable-sockets' '--enable-pcntl' '--with-pspell' '--with-enchant' '--with-gettext' '--with-gd' '--enable-exif' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--with-xsl' '--enable-bcmath' '--enable-mbstring' '--enable-calendar' '--enable-simplexml' '--enable-json' '--enable-hash' '--enable-session' '--enable-xml' '--enable-wddx' '--enable-opcache' '--with-pcre-regex' '--with-config-file-path=/etc/php7/cli' '--with-config-file-scan-dir=/etc/php7/etc' '--enable-cli' '--enable-maintainer-zts' '--with-tsrm-pthreads' '--enable-debug' '--enable-fpm' '--with-fpm-user=www-data' '--with-fpm-group=www-data'

Thread Safety => enabled

pthreads

$ php --version

PHP 7.2.2 (cli) (built: Feb 19 2018 10:04:19) ( ZTS DEBUG ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.2, Copyright (c) 1999-2018, by Zend Technologies

php.ini

Web framework delivered as a C-extension for PHP

phalcon enabled

Author Phalcon Team and contributors

Version 3.3.1

Build Date Jan 10 2018 00:17:28

Powered by Zephir Version 0.10.7-2917ebe8ae

Directive Local Value Master Value

phalcon.db.escape_identifiers On On

phalcon.db.force_casting Off Off

phalcon.orm.cast_on_hydrate Off Off

phalcon.orm.column_renaming On On

phalcon.orm.disable_assign_setters Off Off

phalcon.orm.enable_implicit_joins On On

phalcon.orm.enable_literals On On

phalcon.orm.events On On

phalcon.orm.exception_on_failed_save Off Off

phalcon.orm.ignore_unknown_columns Off Off

phalcon.orm.late_state_binding Off Off

phalcon.orm.not_null_validations On On

phalcon.orm.update_snapshot_on_save On On

phalcon.orm.virtual_foreign_keys On On

After digging further I have concluded that phalcon does not load the pthreads extension. I put the following in public/index.php

if(extension_loaded("pthreads")){

echo 'index pthreads loaded';

}else{

echo 'index pthreads NOT loaded';            

}

Output is: index pthreads NOT loaded

The in: /usr/share/php7.0-phalcon/phalcon/phalcon.ini

I did: [phalcon] extension = phalcon.so

;extension = pthreads.so # does not work!!!!

;extension = /etc/php7/lib/php/extensions/debug-zts-20170718/pthreads.so # does not work

Any suggestion how I can force phalcon to load an extension?



85.5k

https://php.net/manual/en/intro.pthreads.php

there is quite a big warning here, i hope you read it.

you php loads an extension, not phalcon.

their readme https://github.com/krakjoe/pthreads shows how to install and enable it. You probably want to use a seperated version of your web php.

So you need to have 1 php isntalation for your web applications, and another complatly seperated instalation of php just for cli multi threadin

Hello Izo,

Thanks for your input!

I followed these instructions:

https://blog.programster.org/ubuntu16-04-compile-php-7-2-with-pthreads

Then I have pthreads enabled:

cat /etc/php7/cli/php.ini

extension=pthreads.so

zend_extension=opcache.so

cat /etc/php/7.0/apache2/php.ini

extension=pthreads.so

zend_extension=opcache.so

cat /usr/share/php7.0-phalcon/phalcon/phalcon.ini

extension = phalcon.so

extension = pthreads.so

The installation instructions appears to be almost identical between the ones I followed and https://github.com/krakjoe/pthreads

Could you point out what I might have missed?



85.5k

its kind a hard for me to understand the scenario complatly, can you find me on phalcon discord, my nickname there is Izo

https://phalcon.io/discord

i will be on my PC for another 1-2 hours if you are still here