# Shebang parsing

- Thread: https://externals.io/message/57512
- Original archive: https://news-web.php.net/php.internals/57512
- Started by Robert Eisele on 2012-01-25T23:22:57+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

---

## #57512 — Robert Eisele — 2012-01-25T23:22:57+00:00

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

Hi,

I currently work on a daemon implemented in PHP and as such, I want to keep
all configurations in place while the php binary can be used by other cli
scripts with the default /etc/php.ini file. I could recompile PHP and add a
new folder to the folder which is scanned for php.ini files. A better idea
would be a configuration with the shebang like this:

#!/usr/local/php/bin/php -c /var/www/php.ini

Unfortunately, this doesn't work on Linux due to a <del>bug</del>
<ins>feature</ins> which keeps the shebang parameters as one string on
argv[1]. There is already a ticket for this problem:
https://bugs.php.net/bug.php?id=53034

My specific problem could be tackled in two ways:
- Scan "." every time cli is called for a php.ini file or
- Try to make argv interpretation more intelligent and parse/merge shebang
parameters.

The second solution, would also open the possebility to define constants or
make use of all other cli parameters. Well, there's also a quick hack. We
could change php_getopt() in order to make this a valid argument:

php -c=/var/www/php.ini

Anyway, I would provide a patch for the shebang parsing, but I wanted to
put out my feelers what you think about this idea in general. I know, it's
an OS problem, but we could work around this problem very quickly and
improve the usability of cli scripts alot.

Robert

---

## #57514 — keisial@gmail.com — 2012-01-26T00:00:13+00:00

URL: https://externals.io/message/57512#57514 · In reply to: #57512

> My specific problem could be tackled in two ways:
> - Scan "." every time cli is called for a php.ini file or
> - Try to make argv interpretation more intelligent and parse/merge shebang
> parameters.
There are |.user.ini files, but only for CGI/FastCGI
http://es2.php.net/manual/en/configuration.file.per-user.php
|
> The second solution, would also open the possebility to define constants or
> make use of all other cli parameters. Well, there's also a quick hack. We
> could change php_getopt() in order to make this a valid argument:
>
> php -c=/var/www/php.ini
What's wrong with (currently working) php -c/var/www/php.ini ?

---

## #57515 — Clint M Priest — 2012-01-26T00:25:45+00:00

URL: https://externals.io/message/57512#57515 · In reply to: #57514

I've never gotten -d in shebang to work properly, I'd love to see that working.

-----Original Message-----
From: Ángel González [mailto:keisial@gmail.com] 
Sent: Wednesday, January 25, 2012 6:00 PM
To: Robert Eisele
Cc: PHP internals
Subject: Re: [PHP-DEV] Shebang parsing


> My specific problem could be tackled in two ways:
> - Scan "." every time cli is called for a php.ini file or
> - Try to make argv interpretation more intelligent and parse/merge 
> shebang parameters.
There are |.user.ini files, but only for CGI/FastCGI http://es2.php.net/manual/en/configuration.file.per-user.php
|
> The second solution, would also open the possebility to define 
> constants or make use of all other cli parameters. Well, there's also 
> a quick hack. We could change php_getopt() in order to make this a valid argument:
>
> php -c=/var/www/php.ini
What's wrong with (currently working) php -c/var/www/php.ini ?

---

## #57516 — Ferenc Kovacs — 2012-01-26T00:29:12+00:00

URL: https://externals.io/message/57512#57516 · In reply to: #57515

it has a length limit, if I remember correctly it is some reall short value
on linux.
it seems to be 127 character:
http://www.in-ulm.de/~mascheck/various/shebang/

2012/1/26 Clint M Priest <cpriest@zerocue.com>

> I've never gotten -d in shebang to work properly, I'd love to see that
> working.
>
>
-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

---

## #57525 — devis@lucato.it — 2012-01-26T10:06:20+00:00

URL: https://externals.io/message/57512#57525 · In reply to: #57516

Hi,

from
http://stackoverflow.com/questions/4303128/how-to-use-multiple-arguments-with-a-shebang-i-e




   1. Some operating systems simply treat the entire thing as the path.
         After all, in most operating systems, whitespace or dashes
are legal in a
         path.
         2. Some operating systems split at whitespace and treat the first
         part as the path to the interpreter and the rest as
individual arguments.
         3. Some operating systems split at the *first* whitespace and
         treat the front part as the path to the interpeter and the rest as a
         *single* argument (which is what you are seeing).
         4. Some even don't support shebang lines *at all*.

Thankfully, 1. and 4. seem to have died out, but 3. is pretty widespread,
so you simply cannot rely on being able to pass more than one argument.


Devis


2012/1/26 Ferenc Kovacs <tyra3l@gmail.com>

> it has a length limit, if I remember correctly it is some reall short value
> on linux.
> it seems to be 127 character:
> http://www.in-ulm.de/~mascheck/various/shebang/
>
> 2012/1/26 Clint M Priest <cpriest@zerocue.com>
>
> > […]
> --
> Ferenc Kovács
> @Tyr43l - http://tyrael.hu

---

## #57526 — Kiall Mac Innes — 2012-01-26T10:35:51+00:00

URL: https://externals.io/message/57512#57526 · In reply to: #57525

Surely you can detect which operating system you're running on, and have
PHP act accordingly?

(Note: on my phone, haven't read the link!)

Kiall

Sent from my mobile - Sorry for being short.


> Hi,
>
> from
>
> http://stackoverflow.com/questions/4303128/how-to-use-multiple-arguments-with-a-shebang-i-e
>
>
>
>
>   1. Some operating systems simply treat the entire thing as the path.
>         After all, in most operating systems, whitespace or dashes
> are legal in a
>         path.
>         2. Some operating systems split at whitespace and treat the first
>         part as the path to the interpreter and the rest as
> individual arguments.
>         3. Some operating systems split at the *first* whitespace and
>         treat the front part as the path to the interpeter and the rest as
> a
>         *single* argument (which is what you are seeing).
>         4. Some even don't support shebang lines *at all*.
>
> Thankfully, 1. and 4. seem to have died out, but 3. is pretty widespread,
> so you simply cannot rely on being able to pass more than one argument.
>
>
> Devis
>
>
> 2012/1/26 Ferenc Kovacs <tyra3l@gmail.com>
>
> > […]
> value
> > […]

---

## #57530 — keisial@gmail.com — 2012-01-26T20:08:46+00:00

URL: https://externals.io/message/57512#57530 · In reply to: #57526

> Surely you can detect which operating system you're running on, and have
> PHP act accordingly?
>
> (Note: on my phone, haven't read the link!)
>
> Kiall
It's probably not reliable. Note that a simple and completely reliable 
solution
would be instead of having two files (php file + custom php.ini), to use a
third one as launcher:

#!/bin/sh
exec php  -dextension=foo.so -c /path/to/myphp.ini /path/to/myfile.php

---

## #57534 — jpauli — 2012-01-27T13:50:59+00:00

URL: https://externals.io/message/57512#57534 · In reply to: #57530

Some may also read the execve() linux man page.
It has hints about argument parsing and shebangs :)

http://linux.die.net/man/2/execve

Julien.P

2012/1/26 Ángel González <keisial@gmail.com>

> 
>
> > […]
> It's probably not reliable. Note that a simple and completely reliable
> solution
> would be instead of having two files (php file + custom php.ini), to use a
> third one as launcher:
>
> #!/bin/sh
> exec php  -dextension=foo.so -c /path/to/myphp.ini /path/to/myfile.php
