-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Slava Kulpichev
committed
Apr 2, 2014
1 parent
d6f28fe
commit 75ab44c
Showing
7 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
nw_util | ||
Denis Kozik |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
phpize | ||
./configure --enable-nw_util | ||
make | ||
make install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
phpize --clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", ¶ms, &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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\";" |