, 우리가 조언 해 줄 수있는 방법은 없습니다.
젠드가 마침내 임베디드 플랫폼에서 표준이 되었기 때문에 Zend는 마침내 스레드로부터 안전한 PHP를 공개적으로 공개하거나 사람들이 점차 대안을 모색하게 될 것입니다.
// ---------------------------------------------------------
// php.c: G-WAN using PHP scripts
// ---------------------------------------------------------
// To build PHP5:
//
// CFLAGS="-O3" ./configure --enable-embed --enable-maintainer-zts
// --with-tsrm-pthreads --without-pear
// make clean
// make
// sudo make install
/* Installing PHP SAPI module: embed
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/php/man/man1/
Installing PHP CGI binary: /usr/local/bin/
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/lib/php/
[PEAR] Archive_Tar - already installed: 1.3.7
[PEAR] Console_Getopt - already installed: 1.3.0
[PEAR] Structures_Graph- already installed: 1.0.4
[PEAR] XML_Util - already installed: 1.2.1
[PEAR] PEAR - already installed: 1.9.4
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
/home/pierre/Downloads/PHP/php5.4-20/build/shtool install -c ext/phar/phar.phar /usr/local/bin
ln -s -f /usr/local/bin/phar.phar /usr/local/bin/phar
Installing PDO headers: /usr/local/include/php/ext/pdo/ *//*
enabling the 'thread safety' --enable-maintainer-zts option
results in:
error: 'tsrm_ls' undeclared (first use in this function)
*//*
// ---------------------------------------------------------
TEST VALIDATING THIS CODE WITH ONE SINGLE THREAD
(use 2 threads and the PHP runtime crashes)
// ---------------------------------------------------------
weighttp -n 100000 -c 100 -t 1 -k "http://127.0.0.1:8080/?php.c"
finished in 0 sec, 592 millisec, 168744 req/s, 48283 kbyte/s
requests: 100000 total/started/done/succeeded, 0 failed/errored
status codes: 100000 2xx, 0 3xx, 0 4xx, 0 5xx
traffic: 29299985 bytes total, 27599985 bytes http,
1700000 bytes data
// --------------------------------------------------------- */
#pragma include "/usr/local/include/php"
#pragma include "/usr/local/include/php/main"
#pragma include "/usr/local/include/php/TSRM"
#pragma include "/usr/local/include/php/Zend"
#pragma link "/usr/local/lib/libphp5.so"
#include "gwan.h" // G-WAN exported functions
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <php/sapi/embed/php_embed.h>
#include <php/Zend/zend_stream.h>
// ---------------------------------------------------------
static pid_t gettid(void) { return syscall(__NR_gettid); }
// ---------------------------------------------------------
// PHP
// ---------------------------------------------------------
static int ub_write(const char *str, unsigned int str_len TSRMLS_DC)
{
puts(str); // this is the stdout output of a PHP script
return 0;
}
// ---------------------------------------------------------
static void log_message(char * message)
{
printf("log_message: %s\n", message);
}
// ---------------------------------------------------------
static void sapi_error(int type, const char * fmt, ...) { }
// ---------------------------------------------------------
static void php_set_var(char *varname, char *varval)
{
zval *var;
MAKE_STD_ZVAL(var);
ZVAL_STRING(var, varval, 1);
zend_hash_update(&EG(symbol_table), varname, strlen(varname) + 1,
&var, sizeof(zval*), NULL);
}
// ---------------------------------------------------------
static char *php_get_var(char *varname)
{
zval **data = NULL;
char *ret = NULL;
if(zend_hash_find(&EG(symbol_table), varname, strlen(varname) + 1,
(void**)&data) == FAILURE)
{
printf("Name not found in $GLOBALS\n");
return "";
}
if(!data)
{
printf("Value is NULL (not possible for symbol_table?)\n");
return "";
}
ret = Z_STRVAL_PP(data);
return ret;
}
// ---------------------------------------------------------
static int php_init(void)
{
static int once = 0;
if(once) return 0;
once = 1;
static char *myargv[2] = {"toto.php", NULL};
php_embed_module.log_message = log_message;
php_embed_module.sapi_error = sapi_error;
php_embed_module.ub_write = ub_write;
if(php_embed_init(1, myargv PTSRMLS_CC) == FAILURE)
{
printf("php_embed_init error\n");
return 1;
}
return 0;
}
// ---------------------------------------------------------
static void php_shutdown()
{
php_embed_shutdown(TSRMLS_C);
}
// ---------------------------------------------------------
static int php_exec(char *str)
{
zval ret_value;
int exit_status;
zend_first_try
{
PG(during_request_startup) = 0;
// run the specified PHP script file
// sprintf(str, "include (\"% s \ ");", scriptname);
zend_eval_string(str, &ret_value, "toto.php" TSRMLS_CC);
exit_status = Z_LVAL(ret_value);
} zend_catch
{
exit_status = EG(exit_status);
}
zend_end_try();
return exit_status;
}
// ---------------------------------------------------------
__thread char reply_num[8] = {0};
__thread pid_t tid = 0;
int main(int argc, char *argv[])
{
if(!tid)
{
tid = gettid();
s_snprintf(reply_num, 8, "%u", tid);
php_init();
}
xbuf_t *reply = get_reply(argv);
//php_set_var("argv", argv[0]);
php_set_var(reply_num, "");
char fmt[] = //"print(\"from php [$test]\n\");\n"
"$reply%s = \"Hello World (PHP)\";\n";
char php[sizeof(fmt) + sizeof(reply_num) + 2];
s_snprintf(php, sizeof(php), fmt, reply_num);
php_exec(php);
xbuf_cat(reply, php_get_var(reply_num));
return 200;
}
// ---------------------------------------------------------
// End of Source Code
// ---------------------------------------------------------
당신이'젠드 PHP를 실행할 수 없습니다 문에 정교한 수 없습니다 : '나기'의 요청에 따라
, 여기에 G-WAN PHP 모듈이 검토를 위해 젠드에 전송됩니다 '밟아도 안전한 방법으로? 정확히 그게 무슨 뜻이야? PHP는 쓰레드 안전성을 지원한다고 명시하고, 여러분이 쓴 것을 읽은 후에는 PHP가 스레드 안전성 (thread-safety 플래그로 빌드 된 경우)이라는 PHP 팀의 의견을 공유하지 않는 것으로 보입니다. 나는 대답이 정확하거나 오도 된 것 같아서 G-WAN이 나의 목적에 부합 할 수 있는지를 결정할 수 있도록 약간의 설명을 해주길 바란다. –
Zend PHP 런타임을 2 개의 쓰레드와 함께 사용하면 (라이브러리가 없어도) 충돌합니다. 하나의 단일 스레드가 작동하지만 이는 멀티 코어 CPU의 목적을 상쇄합니다. 우리는 젠드에서 여러 번 도움을 요청했지만 (엑스포에서도) 도움을 받았지만 그 문제를 다루는 답변을 얻지 못했습니다. – Gil
PHP 프로젝트에 기여한 공헌자가 많으므로, PHP가 동시 환경에서 작동하도록 고안되어이 문제를 경험한다는 것이 이상하게 느껴진다는 것을 인정해야합니다. 다양한 웹 서버 또는 심지어 독립 실행 형 CLI로도 사용할 수 있습니다. 나는 문제가있을 때 개인적으로 Zend에게 직접 연락하지 않았 음을 인정해야합니다. 문제를 더 자세히 설명하고 싶다면 PHP 작성자와 협력하여 결론에 도달 할 수 있습니까? –