Skip to content

Commit

Permalink
PHP extension repository begin
Browse files Browse the repository at this point in the history
  • Loading branch information
Slava Kulpichev committed Apr 2, 2014
1 parent d6f28fe commit 75ab44c
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nw_util
Denis Kozik
27 changes: 27 additions & 0 deletions Makefile_manual
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

CC = cc
LD = cc
GCC = gcc

PHP_INC =/usr/include/php

INCLUDES = -I . -I$(PHP_INC)/main -I$(PHP_INC)/Zend -I$(PHP_INC)/TSRM -I$(PHP_INC)

CFLAGS = -DLINUX -Wall -O -fPIC
LDFLAGS = -g -shared -Wl

OBJS = nw_util.o

all: nw_util.so

nw_util.so: $(OBJS)
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(CLIBS)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $<
clean:
rm -f ./*.o
rm -f ./*.so
rm -f ./*.lo
rm -f ./*.slo
rm -f ./*.libs

6 changes: 6 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

phpize
./configure --enable-nw_util
make
make install
3 changes: 3 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

phpize --clean
6 changes: 6 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PHP_ARG_ENABLE(nw_util, Enable nw_util support)

if test "$PHP_NW_UTIL" != "no"; then
AC_DEFINE(HAVE_NW_UTIL, 1, [You have nw_util extension])
PHP_NEW_EXTENSION(nw_util, nw_util.c, $ext_shared)
fi
58 changes: 58 additions & 0 deletions nw_util.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "php.h"

PHP_FUNCTION(imagemagic_convert);


const zend_function_entry nw_util_functions[] =
{
PHP_FE(imagemagic_convert, NULL)
{NULL, NULL, NULL}
};

zend_module_entry nw_util_module_entry =
{
STANDARD_MODULE_HEADER,
"nw_util",
nw_util_functions,
NULL,
NULL,
NULL,
NULL,
NULL,
NO_VERSION_YET,
STANDARD_MODULE_PROPERTIES
};

ZEND_GET_MODULE(nw_util);

PHP_FUNCTION(imagemagic_convert)
{
char *params;
int plen;
char *execstr=NULL;
int res=0;
char *cmd="convert ", *pcmd=" > /dev/null 2>&1";
int clen=strlen(cmd), pclen=strlen(pcmd);
char *cptr=NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &params, &plen) == FAILURE) {
return;
}

execstr = malloc(plen+clen+pclen+1);
cptr=execstr;
memcpy(cptr, cmd, clen); cptr+=clen;
memcpy(cptr, params, plen); cptr+=plen;
memcpy(cptr, pcmd, pclen); cptr+=pclen;
// printf("execstr: [%s]\n", execstr);
*cptr='\0';

// popen http://www.sw-at.com/blog/2011/03/23/popen-execute-shell-command-from-cc/

res = system(execstr);
free(execstr);
// printf("res: %d\n", res);
// RETURN_STRING(params, 1);
RETURN_LONG(res);
// RETURN_STRING(execstr, 1);
}
4 changes: 4 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

php -c /etc/php.ini -r "echo \"PHP RUNING TEST:\";"
php -c /etc/php.ini -r "echo \"[\".imagemagic_convert(\"$1\").\"]\n\";"

0 comments on commit 75ab44c

Please sign in to comment.