cphalcon: Strange error after migration to Phalcon 3.0.0

Hello,

yesterday, I migrated my project to Phalcon 3.0 (from 2.1 version). And everything worked fine, except now I got very “randomly” this error:

Fatal error: Uncaught Error: Access to undeclared static property: Phalcon\Di::$_default in C:\xampp-php7-0\htdocs\aplikacija\app\config\services.php:25 Stack trace:
#0 [internal function]: Phalcon\Di->__construct()
#1 C:\xampp-php7-0\htdocs\aplikacija\app\config\services.php(25): Phalcon\Di\FactoryDefault->__construct()
#2 C:\xampp-php7-0\htdocs\aplikacija\public\index.php(25): include('C:\\xampp-php7-0...')
#3 {main}

Next Error: Access to undeclared static property: Phalcon\Di::$_default in C:\xampp-php7-0\htdocs\aplikacija\app\config\services.php:25 Stack trace:
#0 [internal function]: Phalcon\Di->__construct()
#1 C:\xampp-php7-0\htdocs\aplikacija\app\config\services.php(25): Phalcon\Di\FactoryDefault->__construct()
#2 C:\xampp-php7-0\htdocs\aplikacija\public\index.php(25): include('C:\\xampp-php7-0...')
#3 {main} thrown in C:\xampp-php7-0\htdocs\aplikacija\app\config\services.php on line 25

On line 25 in my services.php file is where I create instance of DI factory class:

$di = new FactoryDefault();   ( this is line 25 - error line!)
$di->setShared('config', function () use ($config) {
    return $config;
});

I work on Windows, Xampp v3.2.2 with PHP 7.0.8 and Phalcon 3.0.

Can you help me with this?

Thanks in advance!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 15
  • Comments: 170 (88 by maintainers)

Most upvoted comments

Yet another Window$ dev environment with strange behaviour.

I wouldn’t consider this as a bug unless the issue can be reproduced on production system (i.e. GNU/Linux).

IMHO, just like Phalcon 3.0.0 has dropped support for Oracle RDBMS due to the noted reasons, same should have happened with DLL / Microsoft support.

If Phalcon didn’t want to support developers on the Windows platform, they wouldn’t compile the PHP module for Windows environments. So the solution of “Don’t use windows” doesn’t really apply unless Phalcon completely drops Windows support, which by extension should/would only happen if Zephir dropped Windows support?

I moved from XAMPP + PHP 7.0 (Apache) to XAMPP + PHP 7.0 (FCGI) for testing/semi-production, until a solution is found.

For those who seek a way to convert an existing XAMPP + PHP 7.0 installation, you have to download mod_fcgi to C:\xampp\apache\modules and configure C:\xampp\apache\conf\extra\httpd-xampp.conf as follows. Note that XAMPP is 32 bits.

Although FCGI works better/faster using non-thread-safe version of PHP, it works fine with the thread-safe version included. You don’t need to download a different version of PHP for it to work, and no change to php.ini is needed.

I just cannot understand why people insist so much to use Windows as an application/web server? Sorry, but no one with a grain sense would push that into production. if you use it only for development I guess it’s fine… but with problems described it’s just pain in the ass.

Now start down-voting my post 😃

@Mechzeit That is @Jurigag 's opinion, it’s not the official position about Windows, of course this must be fixed

Don’t use windows xD And/or apache php7 module. Try maybe using fpm and check if it works ?

Actually you can write code in windows - just use vagrant/docker.

@stamster well, more interesting is that @Studentsov don’t have this problem ? 😄

Sometimes people just want to use phalcon on their dev enviroment without using any virutal machine.

Also don’t develop in an environment that is not like your production environment unless you want issues

This is a really strange error. I am using Phalcon 3 on Windows 10, PHP 7.0.8 x64, and similar errors do not occur.

If you have such concerns, then simply move away from Windows as staging environment.

Untitled-1

Yeah the issue is definitely only on PHP 7 (Phalcon 3, and Windows). I have been using Phalcon 3 with PHP 5.6.* since it was released and I’ve had no problems.

As you see above it’s not phalcon problem really.

Try to reload the page many times and the error should appear

solved - I commented out XDebug in my PHP.ini in order for this to work. It could be an extension problem.

My env: Windows 7 + Apache2.4 + PHP 7.0.9

To simulate, run the following code pressing F5 quickly:

$di = new Phalcon\Di();
sleep(1);

As a temporary workaround, you can override Phalcon\Di construct method and translate Zephir to plain PHP code. The error does not occur with the code below:

class Di extends Phalcon\Di
{
    public function __construct()
    {
        $di = self::$_default;
        if (!$di) {
            self::$_default = $this;
        }
    }
}

$di = new Di();
sleep(1);

I meant as you can see above - this is not only phalcon problem - https://github.com/owncloud/core/issues/22370 it even occurs on other enviroments other than windows i guess. Right now no solution, i just posted workaround - don’t use windows, use vagrant/docker until problem fixed.

Environment local testing Windows 10 PHP 7.2.4 ( TS ) Xampp 3.2.2 ( Apache ) Phalcon 3.4

In my case, I upgrade from PHP 5.x to 7. x then I use ajax for loading multi-part in website when render I get Uncaught Error: Access to undeclared static property: Phalcon\Di:😒_default in …

I guess, this is the thread problem because when render website there are multi-thread to execute code. Normally, ajax is run with asynchronous. So, I solve the problem with changing ajax asynchronous to synchronous.

@assadnazar I hope this idea will help you solve the problem.

@assadnazar As noted in this thread before there is an issue with Thread-Safe (TS) version of Phalcon extension. Solution is to use Non-Thread-Safe (NTS) version with Nginx. sergeyklay is working on a fix.

Please use Nginx server on Windows platform. This is best solution.

Thanks to @huoybb. I have resoved the problem.

LoadModule fcgid_module "modules/mod_fcgid.so"

<IfModule fcgid_module>
    FcgidInitialEnv PHPRC                 "C:/xampp/apache/bin"
    FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

    FcgidMaxRequestsPerProcess 1000
    FcgidMaxProcesses          15
    FcgidIOTimeout             120
    FcgidIdleTimeout           120

    AddType application/x-httpd-php .php
    <Files ~ "\.php$>"
        AddHandler   fcgid-script .php
        FcgidWrapper "C:/xampp/php/php-cgi.exe" .php
    </Files>
</IfModule>

you can download the mod_fcgid.so from https://www.apachelounge.com/download/VC14/

install fcgi on apache and setup like below would sovle this problem

LoadModule php7_module "${INSTALL_DIR}/bin/php/php7.1.4/php7apache2_4.dll"

LoadModule fcgid_module modules/mod_fcgid.so

<IfModule fcgid_module>
        FcgidInitialEnv PHPRC "${INSTALL_DIR}/bin/apache/apache2.4.25/bin"
        FcgidInitialEnv PHP_FCGI_MAX_REQUESTS     1000
        FcgidMaxRequestsPerProcess       			1000
        FcgidMaxProcesses             				15
        FcgidIOTimeout             					120
        FcgidIdleTimeout                			        120
        AddType application/x-httpd-php 			.php
        <Files ~ "\.php$>"
          AddHandler fcgid-script .php
          FcgidWrapper "${INSTALL_DIR}/bin/php/php7.1.4/php-cgi.exe" .php
        </Files>
</IfModule>
<VirtualHost *:80>
    DocumentRoot "E:\php\myforum"
    ServerName myforum
    <Directory "E:\php\myforum">
        Require all granted
        Options Indexes FollowSymLinks MultiViews ExecCGI
        AllowOverride all
            Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

If you’re on Windows, why not use IIS? We are all setup here in my office with Windows + IIS + PHP7 (we used to use PHP5.6) + Phalcon 3 (we used to use Phalcon 2) and I have never had a problem (and it is fast).

@vadim-job-hg wrong PHP version? No one said that you need to use 5.2.x stack. What is actually wrong here is using “wrong” OS at first place.

@vadim-job-hg right now your comment is something like what i posted above that you shouldn’t use windows anyway.

PHP5.6 is still supported version as well phalcon 3.0 is supporting both php versions.

I’ve installed Phalcon 3.0 in wampserv with two version of PHP. 5.6.19 and 7.0.4. When I run my phalcon app using php 7.0.4, I got the same error. But I got no error when switched it to php 5.6.19.

Studentsov - i make the same on linux:

phpbrewswitch 7.0.5
phpbrewswitch 5.6.19

Just phpbrew and proper script.

I have the same error. My env: Win 10 x64 + Apache 2.4.23 + PHP 7.0.9 x64 ZTS. Also tried Apache 2.4.18, PHP 7.0.8 x86 ZTS, PHP 7.0.8 x64 ZTS. This error only happens when a lot of requests come. Just create an “index.php” with 2 lines:

use Phalcon\Di\FactoryDefault;
$di = new FactoryDefault();

And keep refreshing this page or use apache ab.exe: ab -n 100 -c 10 “http://localhost/index.php” Then you can see this error in php_error.log.

Update: I tried nginx+php and php cli mode(5.6.19, 7.0.8, 7.0.9), no error appeared. I think this only affects apache+php.

@Jurigag it started happening when people started using PHP 7 with Phalcon. It’s not an issue with PHP 5.

From what I’m seeing so far, this appears to be a thread safety issue that affects all Phalcon versions when used with thread safe php and requests are processed in a muti-threaded manner. For example you won’t encounter this issue through the built-in php server due to it being single-threaded. But something like Apache would be multi-threaded and would encounter this issue. I believe this affects all operating systems and architecture.

I’ll research this some more later and try to come up with a solution.

I managed to refactor this down to a simple test that fails every time and instantly. The entire thing uses only a single file. Run it with: http://localhost/bug.php

https://gist.github.com/Ultimater/4525404c2b48f6d7458b1ca2607d2fb8

I’m currently using this code to pin-point what this affects and doesn’t affect.

A new version was released today but this issue is not resolved yet. Can we have a estimated time period till the patch is released. As i dont know how to used non thread safe version on windows. I just use xampp

The same thing doesn’t happen in cli, happening on apache2.

Same not happening on nginx + php-cgi.exe too. Same php version.

7.3, zend_declare_property_ex()

As far as I understand, the only case when the ZEND_ACC_CONSTANTS_UPDATED gets cleared is when the property is of IS_CONSTANT_AST type (which is a constant array and is not applicable to PHP extensions — it is in the else branch of if (ce->type == ZEND_INTERNAL_CLASS)).

This bug has been fixed after php7.3

Because there is this bug happening specifically on zts mode which is not fixed yet. You use pthreads that you need zts? Because otherwise there is no reason to use zts.

As already wrote - you need to use nts php on cenots.

The issue occurs when simultaneous calls are made. i just tried with 2 ajax calls, and issue occurs. if i run only 1 ajax call by commenting either of the calls, then error does not occur. just for the info, xdebug is not configured on my machine.

Environment: PHP Version 7.2.4 Xampp for Windows 7.2.4 Phalcon 3.3.2

Configuration for OpenServer HTTP Apache-PHP7 module LoadModule fcgid_module modules/mod_fcgid.so <IfModule fcgid_module>

    FcgidInitialEnv PHPRC "%sprogdir%/modules/php/%phpdriver%"
    FcgidInitialEnv PHP_FCGI_MAX_REQUESTS     1000
    FcgidMaxRequestsPerProcess                  1000
    FcgidMaxProcesses                           15
    FcgidIOTimeout                              120
    FcgidIdleTimeout                                    120
    AddType application/x-httpd-php             .php
    <Files ~ "\.php$>"
  AddHandler fcgid-script .php
  FcgidWrapper "%sprogdir%/modules/php/%phpdriver%/php-cgi.exe" .php
    </Files>
</IfModule>

If an web request have been started when another web request have not been finished and the two web request are in the same process, the problem will happen. It may be an thread-safe bug. Linux use the non-thread-safe version, this is why linux have no such problem. I think Phalcon\Di::_default may be compiled non-thread-safe.(All above is a guess)

The best will be if someone can do some vagran tbox/docker to reproduce issue. Maybe @sjinks could then do some digging to figure this out.

@niden Thanks for detailed guide. Anyway, I have followed Zephir windows guide ( https://github.com/phalcon/zephir/blob/master/WINDOWS.md ) and Phalcon “appveyor.yml” which basically says:

> zephir generate
> php build\gen-build.php
> cd build\php%PHP_MAJOR%\safe
> %PHP_DEVPACK%\phpize
> configure --enable-phalcon
> nmake

After manually defining “PHP_SECURITY_FLAGS”, the extension was built successfully and it’s working. In case anyone else wants to test, here are the files (PHP 7.1 32bit TS and NTS): https://www.dropbox.com/s/ks8hxp2hs8tr5af/Phalcon 32bit TS %26 NTS.zip?dl=0

@vprograms60 @otakupahp

Sorry for the late reply.

Can you please run a test if possible? Install PHP 7.0.5 and give it a go. The reason for this suggestion is that the DLLs are compiled against that version so it might be that the PHP DLLs are causing some weird error and therefore Phalcon doesn’t work as expected.

IF that is the case at least we know a) a workaround, b) where the problem lies, so that we can address it better.

https://github.com/phalcon/cphalcon/issues/12056#issuecomment-242985437 https://github.com/owncloud/core/issues/22370

Then why someone don’t have this on windows or have this on something not related to phalcon and windows ?

Yes, I got this issue on PHP7 + Phalcon 3.0 on Windows 7 with WAMP, too Try to switch PHP5.6 and it works now.

For example, I prefer to program in Windows because switching PHP versions, web servers and DBMS I make one click. Isn’t that progress? 😄 Seriously, I am aware of the possible differences of behaviour, so always spend additional testing on a production-like environment. Error when using PHP 7 with Apache I have neither…