Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CLI in PHP

Status
Not open for further replies.

JRBeltman

IS-IT--Management
Feb 5, 2004
290
NL
Hi
I am trying to run a PHP script from the crontab.
Cron actually executes the script, but....
Eventhough I added the CLI path to the start of the php file a test with
Code:
echo php_sapi_name()
returns CGI

My file:
Code:
#!/usr/local/bin/php
<?php
  echo $sapi = php_sapi_name();
?>

I have been told that #!/usr/local/bin/php is the correct path by my hosting provider....

What could be wrong????



JR (IT = Logic (except for a well known OS where it equals luck) -> Back to the Basics!
 
what does your file output? and what do you expect it to output?
 
looks like php was not installed with CLI.

the php manual suggests that the cli will not be installed unless:

disable-cgi is used
a module sapi is chosen during configure; or
make install-cli is run after make install

the cli should be available in sapi/cli/php however.

[this assumes a version of php >= 4.3.0]
 
It is php 4.4.4
Host is dreamhost...

Hmmm, well I dont want CLI to run as the main interpreter.
But in this case I need it for this one file....

I have been reading that I can use enable-cli ? But does this change anything to the default interpreter?

Or should I adjust that path to something like

#!/usr/local/bin/php/sapi/cli/php ??

JR (IT = Logic (except for a well known OS where it equals luck) -> Back to the Basics!
 
can you locate the cli and put a symlink in your /usr/local/bin directory (called something else)?
 
the thing is I am not a linux person...
so, no idea where to locate or how to locate cli...

I was browsing some directories via telnet, found something like /usr/local/bin/php which is empty (mostlikely a symlink as far as I understand that term)...

But how to really find cli? I aint got a clue

JR (IT = Logic (except for a well known OS where it equals luck) -> Back to the Basics!
 
if it's empty, and if it's the directory that your host tells you stores the CLI, then there's your problem!

you could try executing a locate command
Code:
locate php
and see what comes back. it is possible that the locate database has not been initialised. in which case try running
Code:
/usr/libexec/locate.updatedb
 
Wow!

That returned a list soooooo long it didnt fit the screen at all... not by a million times :)

Is there a way of making the locater 'spell' more precise/selective?

JR (IT = Logic (except for a well known OS where it equals luck) -> Back to the Basics!
 
sorry! i guess it's picking up all you php scripts. you could try 'bin/php' and 'cli/php'

 
Tried those.

bin/php gets me the empty php dir.
cli/php or php/cli gives me nothing..

I have written to the dreamhost support to double check it is really installed.... and if so where?

Coz am I correct in thinking it is simply not there?

JR (IT = Logic (except for a well known OS where it equals luck) -> Back to the Basics!
 
it's odd that bin/php is a directory. i'd expect it to be a script.
 
Haha,
stupid me, it is a script indeed..

Not that that helps me..... but hey, it is a script..

Hope it tells you something?

Cheers

JR (IT = Logic (except for a well known OS where it equals luck) -> Back to the Basics!
 
Well,
dreamhost support worked out that you can fool the script a little by using the -C parameter. That combined with -q actually works for this particular 3rd party script I was really trying to get running.

Heck yes, it still runs as CGI though and if you have a solution of getting it to run as CLI that would be much better... but the heat is off (for now)

JR (IT = Logic (except for a well known OS where it equals luck) -> Back to the Basics!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top