PHP 5, and Exec.

Moptop

Registered
I installed PHP on my mac's default apache, from this url - http://www.entropy.ch/software/macosx/php/

And I got the iTunes - to - terminal script from here:
http://www.tuaw.com/2007/04/02/terminal-tip-now-playing-info-from-the-command-line/

Which I would use in php, using exec("./nowplaying");

And it worked.

Then, I replaced my httpd.conf with my mac's default one. Now, the above command doesn't work.. But exec(); works with other terminal commands...

Also, I did try re-installing PHP.

What did I do wrong?
 
I've coded a little bit of PHP before. I have the latest version of the PHP Installer that you linked to installed (Version 5.2.2).

I have not changed anything in httpd.conf.

After creating the nowplaying script, I copied it to /bin so it can be run directly from the Terminal like any other program, and that does work (when running it from the Terminal).

Now if I create a sample PHP script,

Code:
<?php
echo exec('nowplaying');
?>

And put this into a file called "song.php", and place it in my Sites folder, when I visit localhost/~conor/song.php -- the output is blank.

-------

However, that must be a problem individually related to that script, because if I do:

Code:
<?php
echo exec('uptime');
?>

This produces the same result of running "uptime" in the Terminal. It writes it to the page.


Anyone have any insight to the problem with the nowplaying script?
 
Is "nowplaying" in a location that's in your system path? What happens if you include the full pathname to the executable in exec() instead of just the filename?
 
I did try using the Terminal to copy the "nowplaying" script to /bin (from Desktop, where I made the script): sudo cp nowplaying /bin

I can then run "nowplaying" in the Terminal, from any location to get the result. I am not sure if PHP also works in this manner?

I'm going to try entering the direct path to it later when I'm on my Mac.
 
Back
Top