Comments (3)
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.
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.
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)
- ngx_var_get causes nginx to core dump
- [enhancement] Add a timer event
- Simple Demo, Microblog using NGX-PHP (PHP8) and Docker HOT 2
- ngx-php dockerfile need upgrade HOT 4
- rocky linux 8 + php 8.0 + nginx 1.23.1 HOT 4
- Fail with PHP 8.2 HOT 3
- Concrete example from standard nginx.conf? HOT 6
- [Question] Ngx-php internally use forks or threads ? HOT 3
- 一些指令怎么使用呢?没有说明啊
- Async Mysql fail only in this repo :/
- Fix var_dump in tests
- [question] What is the difference with or without _block HOT 1
- Create new release HOT 2
- [question] Can we use ngx_socket_connect() to an upstream? HOT 3
- is this support AWS Linux 2 and PHP 8.2.X
- Ngx-php added as supported SAPI in PHP8.3 HOT 5
- ngx_var_get nginx Signal 11 HOT 4
- Request body > 10kb not response HOT 5
- Fail async MySQL with MySQL v8.4 LTS
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-php.