11 #define PHP_ANCILLARY_VERSION "1.0"
12 #define PHP_ANCILLARY_EXTNAME "ancillary"
14 extern zend_module_entry ancillary_module_entry;
15 #define phpext_ancillary_ptr &ancillary_module_entry
17 // declaration of a custom mop_function()
18 PHP_FUNCTION(ancillary_getstream);
20 // list of custom PHP functions provided by this extension
21 // set {NULL, NULL, NULL} as the last record to mark the end of list
22 static function_entry ancillary_getstream[] = {
23 PHP_FE(ancillary_getstream, NULL)
27 // the following code creates an entry for the module and registers it with Zend.
28 zend_module_entry ancillary_module_entry = {
29 #if ZEND_MODULE_API_NO >= 20010901
30 STANDARD_MODULE_HEADER,
32 PHP_ANCILLARY_EXTNAME,
34 NULL, // name of the MINIT function or NULL if not applicable
35 NULL, // name of the MSHUTDOWN function or NULL if not applicable
36 NULL, // name of the RINIT function or NULL if not applicable
37 NULL, // name of the RSHUTDOWN function or NULL if not applicable
38 NULL, // name of the MINFO function or NULL if not applicable
39 #if ZEND_MODULE_API_NO >= 20010901
40 PHP_ANCILLARY_VERSION,
42 STANDARD_MODULE_PROPERTIES
45 ZEND_GET_MODULE(ancillary)
47 // starting from a unix socket receive a socket from an external process
48 PHP_FUNCTION(ancillary_getstream)
55 if ((headers = calloc(8*1024, 1)) == NULL) {
59 if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream))
62 php_stream_from_zval(stream, &zstream);
64 if (php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fd_in, REPORT_ERRORS) == FAILURE) {
68 if(ancil_recv_fds(fd_in, fd_out, 2) == 0) {
74 sprintf(bf, "zero: [%d] uno: [%d]\n", fd_out[0], fd_out[1]);
75 write(1, bf, strlen(bf));
80 if ((fh = open("/tmp/out_php-anc.txt", O_WRONLY | O_CREAT | O_APPEND)) > -1) {
81 // write(fh, headers, 8*1024);
86 if ((stream = php_stream_fopen_from_fd(fd_out[0], "r+b", NULL)) == NULL) {
90 php_stream_to_zval(stream, return_value);