system() or exec() not working properly

Reply

Join Date: Jun 2009
Posts: 8
Reputation: phpboy is an unknown quantity at this point 
Solved Threads: 0
phpboy's Avatar
phpboy phpboy is offline Offline
Newbie Poster

system() or exec() not working properly

 
0
  #1
Jul 24th, 2009
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 :-
  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
  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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,542
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 137
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

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

 
0
  #2
Jul 24th, 2009
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.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: phpboy is an unknown quantity at this point 
Solved Threads: 0
phpboy's Avatar
phpboy phpboy is offline Offline
Newbie Poster

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

 
0
  #3
Jul 24th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,542
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 137
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

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

 
0
  #4
Jul 24th, 2009
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.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,542
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 137
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

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

 
0
  #5
Jul 24th, 2009
I read that making the following the code can sometimes work...
  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.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: phpboy is an unknown quantity at this point 
Solved Threads: 0
phpboy's Avatar
phpboy phpboy is offline Offline
Newbie Poster

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

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

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

It gives output as :-

  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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,542
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 137
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

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

 
0
  #7
Jul 24th, 2009
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.
  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.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 8
Reputation: phpboy is an unknown quantity at this point 
Solved Threads: 0
phpboy's Avatar
phpboy phpboy is offline Offline
Newbie Poster

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

 
0
  #8
Jul 24th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 497 | Replies: 7
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC