# PHP Source Code Help

- Thread: https://externals.io/message/30907
- Original archive: https://news-web.php.net/php.internals/30907
- Started by Usman S. Ansari on 2007-07-14T06:51:04+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #30907 — Usman S. Ansari — 2007-07-14T06:51:04+00:00

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

I am trying to debug my custom TCP stack which is running under Linux 
OS. Do to some bug in my stack or missing feature I am getting error 
following from php.

failed to open stream

Which I have traced to file: php-4.4.7/main/streams.c and function: 
_php_stream_open_wrapper_ex

        stream = wrapper->wops->stream_opener(wrapper, path_to_open, 
mode, options ^ REPORT_ERRORS,
                 opened_path, context STREAMS_REL_CC TSRMLS_CC);

Error condition occurs when stream is assigned `NULL` from 
wrapper->wops->stream_opener call (see above line). I need some help 
figuring out which function is call by pointer 
wrapper->wops->stream_opener. I tried putting debug statements in some 
functions which are called on pointers (based on different ops (read / 
write / flush operations, etc.), so far I have not hit a function 
pointed by wrapper->wops->stream_opener.

Also, if there is any documentation for understanding php source code.

Thanks

Usman
P.S. I know 4.4.7 is old php, but by system is setup with this version 
for debugging TCP stack (for some reason)

---

## #30919 — Antony Dovgal — 2007-07-14T08:43:34+00:00

URL: https://externals.io/message/30907#30919 · In reply to: #30907

> I am trying to debug my custom TCP stack which is running under Linux 
> OS. Do to some bug in my stack or missing feature I am getting error 
> following from php.
> 
> failed to open stream
> 
> Which I have traced to file: php-4.4.7/main/streams.c and function: 

Don't use it, it's not supported anymore.

> _php_stream_open_wrapper_ex
> 
>         stream = wrapper->wops->stream_opener(wrapper, path_to_open, 
> mode, options ^ REPORT_ERRORS,
>                  opened_path, context STREAMS_REL_CC TSRMLS_CC);
> 
> Error condition occurs when stream is assigned `NULL` from 
> wrapper->wops->stream_opener call (see above line). I need some help 
> figuring out which function is call by pointer 
> wrapper->wops->stream_opener. 

Use any of the debuggers available to step into it and see which function is called.

> I tried putting debug statements in some 
> functions which are called on pointers (based on different ops (read / 
> write / flush operations, etc.), so far I have not hit a function 
> pointed by wrapper->wops->stream_opener.
> 
> Also, if there is any documentation for understanding php source code.

> Usman
> P.S. I know 4.4.7 is old php, but by system is setup with this version 
> for debugging TCP stack (for some reason)
> 


-- 
Wbr, 
Antony Dovgal

---

## #30945 — Usman S. Ansari — 2007-07-15T07:31:15+00:00

URL: https://externals.io/message/30907#30945 · In reply to: #30919

Antony Dovgal wrote:
> > […]
>
> Use any of the debuggers available to step into it and see which 
> function is called.
Since PHP is invoked by Apache server, how can I hockup gcc with php ? 
is there an easy way to do this ?

---

## #30946 — Usman S. Ansari — 2007-07-15T08:18:45+00:00

URL: https://externals.io/message/30907#30946 · In reply to: #30919

> > […]
>
> Use any of the debuggers available to step into it and see which 
> function is called. 
Since PHP is called by apache and error happens right away, is there an 
easy way to invoke php under gdb ?

---

## #30947 — Alexey Zakhlestin — 2007-07-15T08:55:52+00:00

URL: https://externals.io/message/30907#30947 · In reply to: #30946

start "apache -X" inside of gdb


>
> > […]
> Since PHP is called by apache and error happens right away, is there an
> easy way to invoke php under gdb ?
>
> --
> 
> 
>
>


-- 
Alexey Zakhlestin
http://blog.milkfarmsoft.com/

---

## #30954 — Stanislav Malyshev — 2007-07-16T02:06:18+00:00

URL: https://externals.io/message/30907#30954 · In reply to: #30945

> > […]
> Since PHP is invoked by Apache server, how can I hockup gcc with php ? 
> is there an easy way to do this ?

easier way would be to run apache single-process with httpd -X under gdb 
or attach to a certain process with gdb -p.
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #30956 — Usman S. Ansari — 2007-07-16T06:48:38+00:00

URL: https://externals.io/message/30907#30956 · In reply to: #30947

I tried running apache -X under gdb, problem was system (prime client) 
timeout out. I am trying to run SPECweb, I suppose most of the people on 
the list are fimiliar with it.

Anyway I was able to read the code and figure out function called by 
(wrapper->wops->stream_opener), through layers of buffering and function 
calling. My TCP stack is returning one bytes less from the start, so 
http:// 200 is ttp:// 200.

May be it is calling pread to read the data or aio_read (something which 
is not implemented in my stack), Is there a documentation which can help 
me understand the code flow with less pain ?

Usman

Alexey Zakhlestin wrote:
> start "apache -X" inside of gdb
>
> 
> > […]

---

## #30959 — Jani Taskinen — 2007-07-16T08:08:28+00:00

URL: https://externals.io/message/30907#30959 · In reply to: #30954

> > […]
> 
> easier way would be to run apache single-process with httpd -X under gdb 
> or attach to a certain process with gdb -p.

And easiest is to debug with CLI:

# gdb --arg php script-to-debug.php

:)

--Jani
