Re: [PHP-DEV] library calls from within php functions

2002-10-20 Thread Wez Furlong
Hi Tony,

There's not much we can tell you about this unless you post the
rest of the lines of that function.

Perhaps you did not include php.h ?

Note:  always prefer this:

  read(fd, buf, sizeof(buf));

to this:

  read(fd, buf, 1024);

The former is immune to buffer overruns if you change the size of
buf at a later date, and is much more readable.

--Wez. 

On 10/20/02, Tony Leake [EMAIL PROTECTED] wrote:
 Hi, 
 
 I am working on an extension that makes use of the pipe, read and write 
 library calls on a linux platform. 
 
 When I try to put this line 
 read(fd, buf, 1024);
 inside a php function ( PHP_FUNCTION(read_pipe) ) it fails to compile
 with the following warning:
 called object is not a function.
 
 If I move the same line into a standard c function it compiles without
 error. 
 
 So my question is, is there some problem trying to make library calls
 from within php functions? although other calls seem to work fine.
 
 Thanks for any help
 Tony 
 
 
 -- 
 PHP Development Mailing List http://www.php.net/
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DEV] library calls from within php functions

2002-10-20 Thread Tony Leake
Hi, 

I am working on an extension that makes use of the pipe, read and write 
library calls on a linux platform. 

When I try to put this line 
read(fd, buf, 1024);
inside a php function ( PHP_FUNCTION(read_pipe) ) it fails to compile
with the following warning:
called object is not a function.

If I move the same line into a standard c function it compiles without
error. 

So my question is, is there some problem trying to make library calls
from within php functions? although other calls seem to work fine.

Thanks for any help
Tony 


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] library calls from within php functions

2002-10-20 Thread Tony Leake
On Sun, 2002-10-20 at 09:34, Wez Furlong wrote:

Thanks for the fast reply Wez,

 There's not much we can tell you about this unless you post the
 rest of the lines of that function.

See below for the code

 
 Perhaps you did not include php.h ?

Yep thats there, I used exec_skel to create the basic module.
 
 Note:  always prefer this:
 
   read(fd, buf, sizeof(buf));
 
 to this:
 
   read(fd, buf, 1024);

Thanks, done that.

OK, what I'm trying to achieve is basically wrapping pipe, read and
write so in a php script I can create 2 pipes, fork the process using 
pcntl_fork() and have 2 way non blocking communication with more control
than proc_open()

I have so far written this function that creates the pipe and returns an
array of the pipes descriptors:

PHP_FUNCTION(pipe)
{

pipe_r_le_struct *st_pipe_r;
pipe_w_le_struct *st_pipe_w;
zval *read;
zval *write;
int pipe_fd[2];

if(pipe(pipe_fd) 0){
php_error(E_ERROR, Could not create pipe);
}

st_pipe_r=emalloc(sizeof(pipe_r_le_struct));
st_pipe_w=emalloc(sizeof(pipe_w_le_struct));

st_pipe_r-fd=pipe_fd[0];
st_pipe_w-fd=pipe_fd[1];

MAKE_STD_ZVAL(read);
MAKE_STD_ZVAL(write);

ZEND_REGISTER_RESOURCE(read, st_pipe_r, le_pipe_r)
ZEND_REGISTER_RESOURCE(write, st_pipe_w, le_pipe_w)

array_init(return_value);
add_assoc_resource(return_value, read, Z_RESVAL_P(read));
add_assoc_resource(return_value, write, Z_RESVAL_P(write));

}
This function appears to work as expected

and now I'm trying to write functions that will read and write from the
pipe. So far I have this, it isn't finished as you will see.

PHP_FUNCTION(pipe_read)
{
pipe_r_le_struct *st_pipe_r;
zval *read;
zval * res;
char buf[1024];

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, r, res) ==
FAILURE) {
return;
}

ZEND_FETCH_RESOURCE(st_pipe_r, pipe_r_le_struct *, res, -1,
pipe_r, le_pipe_r);

if(!st_pipe_r) RETURN_FALSE;

read(fd, buf, sizeof(buf));
}

I was just testing that it still compiles and it fails on the 
read(fd, buf, sizeof(buf)); line. with the error  
called object is not a function

As I mentioned if I move that line into a c function it compiles fine.

Thanks
Tony 


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] library calls from within php functions

2002-10-20 Thread Wez Furlong
On 10/20/02, Tony Leake [EMAIL PROTECTED] wrote:
 and now I'm trying to write functions that will read and write from the
 pipe. So far I have this, it isn't finished as you will see.
 
 PHP_FUNCTION(pipe_read)
 {
 pipe_r_le_struct *st_pipe_r;
 zval *read;
 zval * res;
 char buf[1024];
 
 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, r, res) ==
 FAILURE) {
 return;
 }
 
 ZEND_FETCH_RESOURCE(st_pipe_r, pipe_r_le_struct *, res, -1,
 pipe_r, le_pipe_r);
 

Try using curly brackets:

if (!st_pipe_r) {
   RETURN_FALSE;
}

Any I take it you mean this:

read(st_pipe_r-fd, buf, sizeof(buf));

 if(!st_pipe_r) RETURN_FALSE;
 
 read(fd, buf, sizeof(buf));
 }

Aside from that, I can't see any obvious mistakes.

--Wez.


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] library calls from within php functions

2002-10-20 Thread Tony Leake
On Sun, 2002-10-20 at 10:07, Wez Furlong wrote:

 Aside from that, I can't see any obvious mistakes.
 

Ok, I solved it. I declared a zval called read, then tried to call the
read function. DOH !

Thanks for your help anyway
Tony


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php