Hangi fonksiyon PHP ile sistem komutları çalıştırmak için tercih edecektir?

3 Cevap php

gibi func("rm -rf /usr/local/)

Hangi 'işlev' Bunu yapmak için kullanacaksınız?

3 Cevap

Bu elde etmek istediğinize bağlıdır.

Eğer idam edildi komutu çıktıya görüntülemek istiyorsanız, passthru hile yapar:

This function should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser. A common use for this is to execute something like the pbmplus utilities that can output an image stream directly.

Eğer bir bütün dize olarak bir değişken komutun çıktısını almak istiyorsanız, kullanabileceğiniz shell_exec (which is the same as using the backtick operator) yapabilirsiniz:

Execute command via shell and return the complete output as a string

Eğer satır satır almak istiyorsanız Ve, kullanacağınız exec :

If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array.

Yani biri hakkında, belgelere bakın - Eğer biraz daha fazla kontrol gerekiyorsa Ve nihayet, sen proc_open kullanacağız biraz daha zor, sanırım.


Still, when using those :

O really gerekli olduğu zaman, ben o sadece kullanmak istiyorum.

PHP'nin exec fonksiyonunu . Other options include system , passthru , and the backtick operator kullanmak istiyorsunuz.

Şahsen ben proc_open iyi bir yaklaşım olduğunu düşünüyorum.

http://php.net/proc%5Fopen

Bu size girdi, çıktı üzerinde çok daha fazla kontrol sağlar ve bunu çıkış durumu ve sistem çağrıları için çoğu diğer komutlar daha fazladır STDOUT diye kontrol edelim. Ayrıca komut çıkar ederken sistemini tutmaz.