我需要在C中获取当前进程的内存使用情况.有人可以在Linux平台上提供如何执行此操作的代码示例吗?
我知道cat /proc/<your pid>/status获取内存的方法,但我不知道如何在C中捕获它.
顺便说一句,这是我正在修改的PHP扩展(授予,我是C新手).如果PHP扩展API中有可用的快捷方式,那将更有帮助.
我正在编写PHP5扩展,虽然我可以用C语言编写,但使用C++并利用STL和Boost更容易.
麻烦的是,我看过的教程只涉及C,我正在寻找一个使用C++的基本例子
这是我到目前为止所尝试的:
[ --enable-hello Enable Hello World support])
if test "$PHP_HELLO" = "yes"; then
AC_DEFINE(HAVE_HELLO, 1, [Whether you have Hello World])
PHP_NEW_EXTENSION(hello, hello.cpp, $ext_shared)
fi
Run Code Online (Sandbox Code Playgroud)
注意我试图将PHP接口的位声明为extern"C"
#ifndef PHP_HELLO_H
#define PHP_HELLO_H 1
extern "C" {
#define PHP_HELLO_WORLD_VERSION "1.0"
#define PHP_HELLO_WORLD_EXTNAME "hello"
PHP_FUNCTION(hello_world);
extern zend_module_entry hello_module_entry;
#define phpext_hello_ptr &hello_module_entry
}
#endif
Run Code Online (Sandbox Code Playgroud)
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_hello.h"
static function_entry hello_functions[] = {
PHP_FE(hello_world, NULL)
{NULL, NULL, NULL}
};
zend_module_entry hello_module_entry = {
#if …Run Code Online (Sandbox Code Playgroud) 我正在检查PHP手册以了解不同类型的PHP扩展(PHP模块).有Zend模块(主要用于PHP专家),内置模块和外部模块.
有没有办法从命令行告诉PHP模块是否已动态加载或是否内置到PHP二进制文件中?
我的意思是:php -m我得到所有加载的模块,但我想知道哪些是内置的,哪些是外部的.
所以我决定为php写一个扩展.一切似乎都很好,除非我遇到一个小问题.
我php-5.4.9有源代码.有一个ext/standard/mail.c很棒的功能文件
PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC)
Run Code Online (Sandbox Code Playgroud)
在我的扩展中,acme.c我已经包括在内
...
#include "php.h"
#include "ext/standard/php_mail.h"
#include "php_ini.h"
...
Run Code Online (Sandbox Code Playgroud)
所以php_mail你感觉良好,工作正常.但是,显然,我想使用从mail.c第101行开始到189结束的代码(http://pastie.org/5444192 5-93对应的行中的代码).所以我抓住了自己的想法(虽然在某些方面很尴尬)为什么不打电话PHP_FUNCTION(mail)?到目前为止我找不到那些宏,实际上我想知道实现这个想法的最佳方法.
我内心的zend工程师(新手)建议我使用call_user_function
ZEND_API int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, zend_uint param_count, zval *params[] TSRMLS_DC);
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何称呼它.
这个问题!如何(非常欢迎mail函数的例子)调用由?定义的函数?PHP_FUNCTION
我已经从ubuntu卸载了php7及其所有模块,当我尝试重新安装模块时,我得到每个php模块的以下错误,虽然模块已安装,但由于此错误,它未激活且我无法使用他们.有什么方法可以解决这个问题吗?每个模块的错误(安装时):
Not replacing deleted config file /etc/php/7.0/mods-available/intl.ini
WARNING: Module [module name] ini file doesn't exist under /etc/php/7.0/mods-available
WARNING: Module [module name] ini file doesn't exist under /etc/php/7.0/mods-available
WARNING: Module [module name] ini file doesn't exist under /etc/php/7.0/mods-available
Run Code Online (Sandbox Code Playgroud) 当我运行命令
php -v
Run Code Online (Sandbox Code Playgroud)
这个错误出现了
PHP警告:PHP启动:无法加载动态库'/usr/lib/php/modules/module.so' - /usr/lib/php/modules/module.so:无法打开共享对象文件:没有这样的文件或目录在Unknown第0行PHP 5.3.3(cli)(建于:2013年2月22日02:37:06)
是否有可能在PHP中获得扩展版本?
get_loaded_extensions 仅返回已加载的扩展名称,但不返回版本:(
我有Docker(docker-compose)的问题.我想使用安装一些PHP扩展docker-compose.yml,但我无法做到这一点,因为我的.yml有FROM ubuntu和没有FROM php.有什么方法可以实现或访问docker-php-ext-install?
FROM ubuntu:16.04
RUN apt -yqq update
RUN apt -yqq install nginx iputils-ping
RUN docker-php-ext-install pdo pdo_mysql mbstring
WORKDIR /usr/local/src
COPY docker/nginx/dev.conf /etc/nginx/conf.d/dev.conf
COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf
CMD ["nginx"]
Run Code Online (Sandbox Code Playgroud)
version: "2"
services:
mariadb:
image: mariadb
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=1
- MYSQL_ROOT_PASSWORD=
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "8080:80"
restart: always
environment:
- PMA_HOST=mariadb
links:
- mariadb
php:
image: php:7.1.1-fpm
ports:
- "9000:9000"
volumes:
- .:/dogopic
links:
- mariadb
nginx:
build: . …Run Code Online (Sandbox Code Playgroud) 我正在尝试为个人项目创建PHP扩展.除了上面文章中的内容之外,我对zend_engine一无所知,而且我的C技能已经过时了10年,并且只是学术性的.所有这些都是说"如果我好像在问一个愚蠢的问题,我可能就是".
是否可以在我自己的扩展中调用其他PHP扩展中的函数,或者每个PHP扩展都被认为是孤岛,而没有深入了解系统的其他部分?如果这是可能的,这是常见做法还是坏主意™?
也就是说,我知道我可以用这样的东西返回一个字符串.
PHP_FUNCTION(hello_world)
{
char *str;
str = estrdup("Hello World");
RETURN_STRING(str, 0);
}
Run Code Online (Sandbox Code Playgroud)
我希望能够返回一个SimpleXML元素或一个DomDocument元素.谷歌搜索已经证明是困难的,因为扩展开发并没有那么多,并且有很多标准的PHP使用.
php-extension ×10
php ×7
c ×4
c++ ×1
docker ×1
dockerfile ×1
gcc ×1
linux ×1
memory ×1
php-7 ×1