Giter Site home page Giter Site logo

Comments (3)

Qwoker avatar Qwoker commented on June 9, 2024

Okay, declare error i fixed with

if (!class_exists('test')) {
     class test 
     {
...
}

now the question remains, how to initialize variables in init_worker so that they are visible and available for change in other workers, for example, in rewrite

from ngx-php.

joanhey avatar joanhey commented on June 9, 2024

Please, don't use class_exists(), it isn't a solution to the problem.

The problem is basic knowledge of PHP.

Include

If you include the same file two or more times in a php file, the error will always exist of cannot declare class (function, ...)

Try this in any PHP SAPI (php-fpm, cli, ...)

function rewrite() {
     include "/etc/nginx/php/index.php";
}

rewrite();
rewrite();
....

Ngx-php is embeded PHP in Nginx, so the application is persistent. Once included a file, it isn't necessary to include again or you will have that problems.

A simple fix is use include_once , or better because you will use it always, is a normal include in the init_worker.
The init_worker only run the first time, and all the code is always available in any place in your workers.

Namespaces

The second error Class 'memcached' not found, it's also normal.
You are calling a class: memcached, that don't exist, because in your included file you only have the class: ngxphp\memcached\memcached

Examples

Check the files in the Techempower benchmark. Exist examples with global variables, with classes, ....
https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/PHP/php-ngx

from ngx-php.

Qwoker avatar Qwoker commented on June 9, 2024

Yes, your right.
If i include once on init_worker is good, work!
Latest question how to collect data in memory PHP. Example do $dataArray = array() in init_worker and call it in content_by_php block and possible to modify $dataArray (unset, push and etc functions for arrays)

from ngx-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.