943,696 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2168
  • PHP RSS
Jul 24th, 2009
0

system() or exec() not working properly

Expand Post »
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 :-
PHP Syntax (Toggle Plain Text)
  1. 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
PHP Syntax (Toggle Plain Text)
  1. 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
phpboy is offline Offline
10 posts
since Jun 2009
Jul 24th, 2009
0

Re: system() or exec() not working properly

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.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Jul 24th, 2009
0

Re: system() or exec() not working properly

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 ?
Last edited by phpboy; Jul 24th, 2009 at 8:35 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
phpboy is offline Offline
10 posts
since Jun 2009
Jul 24th, 2009
0

Re: system() or exec() not working properly

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.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Jul 24th, 2009
0

Re: system() or exec() not working properly

I read that making the following the code can sometimes work...
php Syntax (Toggle Plain Text)
  1. exec('youtube-dl http://www.youtube.com/watch?v=ZMhMZ8Ciyxw -o /home/video.flv');
  2. 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.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Jul 24th, 2009
0

Re: system() or exec() not working properly

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

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

It gives output as :-

PHP Syntax (Toggle Plain Text)
  1. 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.
Last edited by phpboy; Jul 24th, 2009 at 9:22 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
phpboy is offline Offline
10 posts
since Jun 2009
Jul 24th, 2009
0

Re: system() or exec() not working properly

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.
PHP Syntax (Toggle Plain Text)
  1. 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.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Jul 24th, 2009
0

Re: system() or exec() not working properly

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
phpboy is offline Offline
10 posts
since Jun 2009
Oct 10th, 2010
0
Re: system() or exec() not working properly
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lipo is offline Offline
1 posts
since Oct 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Probably n00b question | $_POST key unset?
Next Thread in PHP Forum Timeline: Age Verification Script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC