pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Pqsocket not implemented in PHP
5+ messages / 2 participants
[nested] [flat]

* Pqsocket not implemented in PHP
@ 2005-06-30 09:35 Nick Stone <nick@harelane.com>
  2005-06-30 10:10 ` Re: Pqsocket not implemented in PHP Volkan YAZICI <volkan.yazici@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Nick Stone @ 2005-06-30 09:35 UTC (permalink / raw)
  To: pgsql-php

Hi,

I tried this question on the PHP lists but didn't get anywhere so I'm hoping
you maybe able to help.

I'm currently implementing a standalone app using php cli. Part of the app
connects to Postgres and waits for a notification using the "Listen
<tablename>" SQL. In the postgres C lib there is a function called
"Pqsocket" which returns the file-descriptor of the socket connection to
Postgres. With this I can use a simple select server to sleep on this
interface and others in the application.

Does anybody now of a patch to make this available under PHP or does the
structure of PHP code effectively make this type approach impossible?
Alternatively if I've just missed the function would somebody point me in
the right direction - I was kind of hoping (until I read the man pages more
closely) that pg_port was the function that wrapped the Pqsocket command but
sadly not!

If I need to wite one then I'll do that and post it back if that's useful
but just in case somebody has done it before...

Thanks

Nick





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Pqsocket not implemented in PHP
  2005-06-30 09:35 Pqsocket not implemented in PHP Nick Stone <nick@harelane.com>
@ 2005-06-30 10:10 ` Volkan YAZICI <volkan.yazici@gmail.com>
  2005-06-30 10:55   ` Re: Pqsocket not implemented in PHP Nick Stone <nick@harelane.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Volkan YAZICI @ 2005-06-30 10:10 UTC (permalink / raw)
  To: Nick Stone <nick@harelane.com>; +Cc: pgsql-php

Hi,

On 6/30/05, Nick Stone <nick@harelane.com> wrote:
> I'm currently implementing a standalone app using php cli. Part of the app
> connects to Postgres and waits for a notification using the "Listen
> <tablename>" SQL. In the postgres C lib there is a function called
> "Pqsocket" which returns the file-descriptor of the socket connection to
> Postgres. With this I can use a simple select server to sleep on this
> interface and others in the application.
> 
> Does anybody now of a patch to make this available under PHP or does the
> structure of PHP code effectively make this type approach impossible?

You can write a very simple patch returns socket FD using PQsocket().
But, AFAIC, it's not as simple as it seems to listen a socket using
just its FD value. As I understand from the source code, resource
required by socket_open() function has its own internal struct
representation, which means you need to be familiar with PHP internal
data types and mechanism before writing a patch. Therefore, it's not
impossible to implement such a feature, but, to be honest, it needs a
hard work.

IMHO, you can enter a loop with pg_last_notice() by using usleep(). I
won't think it'd cost so much system resource for you.

Regards.



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Pqsocket not implemented in PHP
  2005-06-30 09:35 Pqsocket not implemented in PHP Nick Stone <nick@harelane.com>
  2005-06-30 10:10 ` Re: Pqsocket not implemented in PHP Volkan YAZICI <volkan.yazici@gmail.com>
@ 2005-06-30 10:55   ` Nick Stone <nick@harelane.com>
  2005-06-30 11:38     ` Re: Pqsocket not implemented in PHP Volkan YAZICI <volkan.yazici@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Nick Stone @ 2005-06-30 10:55 UTC (permalink / raw)
  To: 'Volkan YAZICI' <volkan.yazici@gmail.com>; +Cc: pgsql-php

Hi,

Thanks for the response - though I'm a bit confused the FD is all that is
required for the select call - so I think what you're saying is that the
postgres socket open mechanism isn't the same in php as the postgres C
development library.

I say this because I've implemented this exact mechanism in C++ before
without problem so I'm really not quite following - sorry. Is it that PHP
implements the underlying socket mechanism in a different way? I guess I'm
not quite understanding could you give me a few more details of the PHP
mechanism.

Many thanks

Nick

-----Original Message-----
From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org]
On Behalf Of Volkan YAZICI
Sent: 30 June 2005 11:11
To: Nick Stone
Cc: pgsql-php@postgresql.org
Subject: Re: [PHP] Pqsocket not implemented in PHP

Hi,

On 6/30/05, Nick Stone <nick@harelane.com> wrote:
> I'm currently implementing a standalone app using php cli. Part of the 
> app connects to Postgres and waits for a notification using the 
> "Listen <tablename>" SQL. In the postgres C lib there is a function 
> called "Pqsocket" which returns the file-descriptor of the socket 
> connection to Postgres. With this I can use a simple select server to 
> sleep on this interface and others in the application.
> 
> Does anybody now of a patch to make this available under PHP or does 
> the structure of PHP code effectively make this type approach impossible?

You can write a very simple patch returns socket FD using PQsocket().
But, AFAIC, it's not as simple as it seems to listen a socket using just its
FD value. As I understand from the source code, resource required by
socket_open() function has its own internal struct representation, which
means you need to be familiar with PHP internal data types and mechanism
before writing a patch. Therefore, it's not impossible to implement such a
feature, but, to be honest, it needs a hard work.

IMHO, you can enter a loop with pg_last_notice() by using usleep(). I won't
think it'd cost so much system resource for you.

Regards.

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Pqsocket not implemented in PHP
  2005-06-30 09:35 Pqsocket not implemented in PHP Nick Stone <nick@harelane.com>
  2005-06-30 10:10 ` Re: Pqsocket not implemented in PHP Volkan YAZICI <volkan.yazici@gmail.com>
  2005-06-30 10:55   ` Re: Pqsocket not implemented in PHP Nick Stone <nick@harelane.com>
@ 2005-06-30 11:38     ` Volkan YAZICI <volkan.yazici@gmail.com>
  2005-06-30 12:25       ` Re: Pqsocket not implemented in PHP Nick Stone <nick@harelane.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Volkan YAZICI @ 2005-06-30 11:38 UTC (permalink / raw)
  To: Nick Stone <nick@harelane.com>; +Cc: pgsql-php

Hi,

On 6/30/05, Nick Stone <nick@harelane.com> wrote:
> I'm a bit confused the FD is all that is
> required for the select call - so I think what you're saying is that the
> postgres socket open mechanism isn't the same in php as the postgres C
> development library.

No. PHP has an internal struct type to record `resource's. (As you
know, resources are data sources for other functions and they're
specific to PHP.) Therefore, it's not just passing PQsocket() value to
select() function. I'm not very experienced in the PHP internals, but
AFAIC, you need to store socket FD in a specific struct and use other
Zend API calls to proccess 'em.

To sum up, I'd advice you to take a look at ext/socket/socket.c in PHP
source code for a better point of view.

> I say this because I've implemented this exact mechanism in C++ before
> without problem so I'm really not quite following - sorry.

In C++, you just passed PQsocket() value to select() condition. But in
PHP it's not as easy as this. You need to store PQsocket() value in a
specific struct. Let me explain this in PHP way:

When we look at socket_create() function:
  resource socket_create ( int domain, int type, int protocol )
socket_create() doesn't return an `int' for socket FD, it returns a
socket `resource'. That's what I try to mean with "PHP's internal data
source representation".

Regards.



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Pqsocket not implemented in PHP
  2005-06-30 09:35 Pqsocket not implemented in PHP Nick Stone <nick@harelane.com>
  2005-06-30 10:10 ` Re: Pqsocket not implemented in PHP Volkan YAZICI <volkan.yazici@gmail.com>
  2005-06-30 10:55   ` Re: Pqsocket not implemented in PHP Nick Stone <nick@harelane.com>
  2005-06-30 11:38     ` Re: Pqsocket not implemented in PHP Volkan YAZICI <volkan.yazici@gmail.com>
@ 2005-06-30 12:25       ` Nick Stone <nick@harelane.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Nick Stone @ 2005-06-30 12:25 UTC (permalink / raw)
  To: 'Volkan YAZICI' <volkan.yazici@gmail.com>; +Cc: pgsql-php

Ok that's fair enough - I was concerned that the internal structure of PHP
might be a stumbling block - also since nearly every other function was
implemented I suspected there had to be a good reason why that's not been. I
can easily write the code a different way.

Thanks for your help

Nick 

-----Original Message-----
From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org]
On Behalf Of Volkan YAZICI
Sent: 30 June 2005 12:38
To: Nick Stone
Cc: pgsql-php@postgresql.org
Subject: Re: [PHP] Pqsocket not implemented in PHP

Hi,

On 6/30/05, Nick Stone <nick@harelane.com> wrote:
> I'm a bit confused the FD is all that is required for the select call 
> - so I think what you're saying is that the postgres socket open 
> mechanism isn't the same in php as the postgres C development library.

No. PHP has an internal struct type to record `resource's. (As you know,
resources are data sources for other functions and they're specific to PHP.)
Therefore, it's not just passing PQsocket() value to
select() function. I'm not very experienced in the PHP internals, but AFAIC,
you need to store socket FD in a specific struct and use other Zend API
calls to proccess 'em.

To sum up, I'd advice you to take a look at ext/socket/socket.c in PHP
source code for a better point of view.

> I say this because I've implemented this exact mechanism in C++ before 
> without problem so I'm really not quite following - sorry.

In C++, you just passed PQsocket() value to select() condition. But in PHP
it's not as easy as this. You need to store PQsocket() value in a specific
struct. Let me explain this in PHP way:

When we look at socket_create() function:
  resource socket_create ( int domain, int type, int protocol )
socket_create() doesn't return an `int' for socket FD, it returns a socket
`resource'. That's what I try to mean with "PHP's internal data source
representation".

Regards.

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend






^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2005-06-30 12:25 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-06-30 09:35 Pqsocket not implemented in PHP Nick Stone <nick@harelane.com>
2005-06-30 10:10 ` Volkan YAZICI <volkan.yazici@gmail.com>
2005-06-30 10:55   ` Nick Stone <nick@harelane.com>
2005-06-30 11:38     ` Volkan YAZICI <volkan.yazici@gmail.com>
2005-06-30 12:25       ` Nick Stone <nick@harelane.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox