# own php function

- Thread: https://externals.io/message/32094
- Original archive: https://news-web.php.net/php.internals/32094
- Started by Marten Lehmann on 2007-09-07T17:57:53+00:00
- Messages: 5
- 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

---

## #32094 — Marten Lehmann — 2007-09-07T17:57:53+00:00

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

Hello,

I would like to create an own php function which just prints a certain 
report as `phpinfo()` does.

The function shall not be included into the general php code, I just 
want to patch my own installation. Where would be a good place for the 
function? I don't want to create an extention which would have to be 
included into the configure script, I guess thats too much work. The 
function shall be able to access the Host-header of the webserver.

Regards
Marten

---

## #32095 — David Coallier — 2007-09-07T18:24:45+00:00

URL: https://externals.io/message/32094#32095 · In reply to: #32094

> Hello,
>
> I would like to create an own php function which just prints a certain
> report as `phpinfo()` does.
>
> The function shall not be included into the general php code, I just
> want to patch my own installation. Where would be a good place for the
> function? I don't want to create an extention which would have to be
> included into the configure script, I guess thats too much work. The
> function shall be able to access the Host-header of the webserver.
>
> Regards
> Marten
>
> --
> 
> 
>
>

You could make your own extension.. in order to write them (Because
after writting one you realize you need more) you should be using
either that book by Sara:
http://www.amazon.com/dp/067232704X?tag=libssh2projec-20&camp=14573&creative=327641&linkCode=as1&creativeASIN=067232704X&adid=01HQSM6RF0V2X97Y0VPW&

Or

Start by reading:

http://devzone.zend.com/article/1021-Extension-Writing-Part-I-Introduction-to-PHP-and-Zend

And I would probably direct you towards pecl-dev@lists.php.net

The reason I am mentioning to make your own extension is to save you
the hassle of migrating from a version to another. If you make your
extension you can easily package it, and when you recompile/re-install
php, you just pecl install MyOwnExtension or such.





-- 
David Coallier,
Founder & Software Architect,
Agora Production (http://agoraproduction.com)
51.42.06.70.18

---

## #32100 — johannes@php.net — 2007-09-07T19:18:18+00:00

URL: https://externals.io/message/32094#32100 · In reply to: #32094

Hi Marten,

On Friday 07 September 2007 07:57:53 pm Marten Lehmann wrote:
> Hello,
>
> I would like to create an own php function which just prints a certain
> report as `phpinfo()` does.
>
> The function shall not be included into the general php code, I just
> want to patch my own installation. Where would be a good place for the
> function? I don't want to create an extention which would have to be
> included into the configure script, I guess thats too much work. The
> function shall be able to access the Host-header of the webserver.

A custom extension looks like the perfect place for such a thing since changes 
in PHP will less likely break it and you can simply copy it from PHP version 
to PHP version without having to care aobut changes in PHP...

johannes

> Regards
> Marten



-- 
Johannes Schlüter
http://schlueters.de

---

## #32102 — Hartmut Holzgraefe — 2007-09-07T20:04:44+00:00

URL: https://externals.io/message/32094#32102 · In reply to: #32094

Marten Lehmann wrote:
> I would like to create an own php function which just prints a certain 
> report as `phpinfo()` does.
> 
> The function shall not be included into the general php code, I just 
> want to patch my own installation. Where would be a good place for the 
> function? I don't want to create an extention which would have to be 
> included into the configure script, I guess thats too much work. The 
> function shall be able to access the Host-header of the webserver.


I'd also recommend that you wrap your function into an
extension of its own, it is not as hard as it seems ...

(warning, shameless plug to follow as usual)

... especially if you let pecl-gen take care of all the
infrastructure work so that you can focus on the desired
functionality.

Assuming that your function does not take any parameter
and does not return anything your pecl-gen input file
would look like this:

<?xml version="1.0"?>
<extension name="myinfo">
   <function name="myinfo">
     <proto>void myinfo(void)</proto>
     <code>
<![CDATA[
         php_printf("your output here\n");
]]>
     </code>
   </function>
</extension>

Once you've installed CodeGen_PECL from PEAR
you can create a working extension from this
using the following sequence of commands:

   pecl-gen myinfo.xml
   cd myinfo
   phpize
   configure
   make
   sudo make install

After that you can load the extension in
php.ini using

   extension=myinfo.so

For more details on pecl-gen see:

   http://php-baustelle.de/CodeGen_PECL/manual.html

-- 
Hartmut Holzgraefe, Principal Support Engineer
               .
Discover new MySQL Monitoring & Advisory features at:
http://www.mysql.com/products/enterprise/whats_new.html

Hauptsitz: MySQL GmbH, Dachauer Str.37, 80335 München
Geschäftsführer: Kaj Arnö - HRB München 162140

---

## #32144 — Marten Lehmann — 2007-09-09T21:06:48+00:00

URL: https://externals.io/message/32094#32144 · In reply to: #32102

Hello,

thanks for all ideas, I will have a look at it very shortly.

Regards
Marten
