Hello.
I have a linux VPS which is running ubuntu 8.04

I want to execute some command to the terminal, for doing that i use system() or exec() function.

The functions are working properly at localhost, but aren't working properly on the VPS.

Let's say, i have a command :-

youtube-dl http://www.youtube.com/watch?v=ZMhMZ8Ciyxw -o /home/video.flv

This command downloads the video's flv
I use following code in my php code

system('youtube-dl http://www.youtube.com/watch?v=ZMhMZ8Ciyxw -o /home/video.flv');

This should work properly. The command is executed in terminal but i do not receive the output as desired.

There are no error messages, just output from terminal which comes before the actual downloading of the video starts.

Any help would be really appreciated.
Thanks.

Recommended Answers

All 8 Replies

Just to let you know I find it is best to not use the system command line functions. My reason - I find that some servers just aren't compatible with these functions due to security policies and can even crash a server if the right settings are set on the server. So perhaps if you explain what you are trying to make the command do (like copying a movie) and I will try and find an alternative. I know the file_get_contents() and file_put_contents() are good for copying files on other servers.

Hi cwarn23. Thanks for your reply.
Probably what i'm looking for is to download a youtube video and edit it using mencoder.

So i probably want to use youtube-dl and mencoder, which are installed on my VPS

I face same problem using exec(), sytem() or passthru()
If commands are run manually using ssh, it works fine.
But if done through php, it doesn't work fully and properly.

Where can the problem be ? :)

If you own a VPS (Virtual Private Server) like I do and really want to use those functions then you will need to find the security policies for php and set the security policies to allow php to interact with the core system. I think it's mainly a thing that's not enabled by default due to security reasons but I myself am not sure on how to enable these security policies. I'll google a bit for you to see if I can find such info.

I read that making the following the code can sometimes work...

exec('youtube-dl http://www.youtube.com/watch?v=ZMhMZ8Ciyxw -o /home/video.flv');
exec('exit(0)');

Also I read that there is some setting in the php.ini file for the exec function but I can't seem to find it.

I tried using exit(0) but it doesn't made any change.
One more thing...for example we execute a command as :-

echo exec('youtube-dl http://www.youtube.com/watch?v=ZMhMZ8Ciyxw -o /home/video.flv');

It gives output as :-

Video data found at http://v9.lscache3.googlevideo.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Cburst%2Cfactor&itag=5&ipbits=0&signature=CAC74228191224D270888F734075E7113F0F07A4.C33E764E27F6D8021E8D79804B38232BFF4DEF3D&sver=3&expire=1248462000&key=yt1&factor=1.25&burst=40&id=7e8e3d7fc6e4e43d

and then the browser stops.
The execution stops exactly when the process starts (i.e when it displays the actual download percentage..like speed and percentage of download completion)

While doing same on localhost, it works fine.
Same happens with mencoder...the output displayed is upto when the real conversion of video starts.

I think there need to be some setting to be changed in php.ini
I will be looking in.

Maybe php doesn't have the permissions to access the base of the home folder where as when you do it through the command terminal you are logged in as administrator. So try something like the following but replace the end address with the address to your web directory.

echo exec('youtube-dl http://www.youtube.com/watch?v=ZMhMZ8Ciyxw -o /home/user/public_html/video.flv');

So the public_html folder is the base of your website.

Ya, i think you are correct.
But as of now, i dont have any user (rather than root)
let me create one and make a sub root at public_html

Will report back tomorrow.
Thanks for your help. let's see how it goes.

Hi Phpboy,

Did you find a solution to this issue?

I have the same problem now. Can you email me the solution to:
info@lipo-technologies.com

Thanks,
Larry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.