# how to determine errno on user space?

- Thread: https://externals.io/message/66885
- Original archive: https://news-web.php.net/php.internals/66885
- Started by chobie on 2013-04-02T00:11:24+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #66885 — chobie — 2013-04-02T00:11:24+00:00

URL: https://externals.io/message/66885#66885

Hi, I'm writing some socket client (fluentd client) with PHP and I have a
question.

I want to retry fwrite or some socket function when I met recoverable errno
(e.g, EAGAIN). but PHP does not have any function to determine errno as far
as I known.

what is the correct way to handle errno?
I'd like to write robust client with PHP but I don't have good idea to
determine errno.


I'm thinking and thinking about this issue long time. I inspired ruby's
errno module (
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_m_errno.html) and I
just wrote errno extension to check my idea. I think importing errno module
is not a bad idea.

https://github.com/chobie/php-errno/blob/master/php_errno.c
(currently, this lacks const_missing feature so this does not work on some
platform. )


Could you help me out if you guys have good solution about handling socket
error?

Thanks,
Shuhei

---

## #66929 — Gustavo Lopes — 2013-04-03T21:34:42+00:00

URL: https://externals.io/message/66885#66929 · In reply to: #66885

> Hi, I'm writing some socket client (fluentd client) with PHP and I have a
> question.
>
> I want to retry fwrite or some socket function when I met recoverable  
> errno (e.g, EAGAIN). but PHP does not have any function to determine  
> errno as far as I known.
>
> what is the correct way to handle errno?
> I'd like to write robust client with PHP but I don't have good idea to
> determine errno.
>

The sockets extension has `socket_last_error()` to get the errno value after  
the last operation on the passed in socket.

The stream functions don't really handle this in a consistent fashion. For  
instance, `stream_socket_client()` can take a parameter by reference where  
to write the errno value, but other functions do not give such information  
and can only inform the user about the specific error that occurred via  
the a warning, which is not very friendly for programatically extracting  
the cause. I'd recommend that you use the sockets extension, unless you  
need encryption.

As to your approach, I don't really like it. PHP does not have  
enumerations, and the approach of creating a very large number of classes  
for this purpose is unprecedented in the PHP codebase.

-- 
Gustavo Lopes

---

## #66994 — chobie — 2013-04-06T06:36:31+00:00

URL: https://externals.io/message/66885#66994 · In reply to: #66929

The socket extension has another problem. it cannot create persistent
connection.
this is a big problem on large web application.

> As to your approach, I don't really like it. PHP does not have
enumerations, and the approach of creating a very large number of  classes
for this purpose is unprecedented in the PHP codebase.

that approach is just came up and working sample. I'm looking for phpish
errno handling.

at least I need errno constants. you know errno depends platform. if I
hardcoded errno magic number on my library,
it works some platform but it might not work another platform (e.g
windows...)

I can choose to ignore errno on my library. but I'd like to improve PHP. as
PHP has libevent and some ev* extension
so adding errno feature is not a bad idea i think.


On Thu, Apr 4, 2013 at 6:34 AM, Gustavo Lopes <glopes@nebm.ist.utl.pt>wrote:

> 
>
>  Hi, I'm writing some socket client (fluentd client) with PHP and I have a
> > […]
> The sockets extension has `socket_last_error()` to get the errno value after
> the last operation on the passed in socket.
>
> The stream functions don't really handle this in a consistent fashion. For
> instance, `stream_socket_client()` can take a parameter by reference where to
> write the errno value, but other functions do not give such information and
> can only inform the user about the specific error that occurred via the a
> warning, which is not very friendly for programatically extracting the
> cause. I'd recommend that you use the sockets extension, unless you need
> encryption.
>
> As to your approach, I don't really like it. PHP does not have
> enumerations, and the approach of creating a very large number of classes
> for this purpose is unprecedented in the PHP codebase.
>
> --
> Gustavo Lopes
