Alternate to PHP exec() function
Asked Answered
B

4

11

Currently I am using:

exec("zcat $filename", $output)

To uncompress a .Z type file but unfortunately my hosting company has now disabled this function.

Is there a workaround?

$pathtofile = "filename.lis.Z";
exec("zcat $pathtofile", $output);
Baluchistan answered 27/9, 2011 at 6:32 Comment(8)
Unfortunately the compress format .Z is not understood by zlib itself, so PHPs gzuncompress() won't work. If you can't use exec anymore, you'll have to adapt your file sources. Use gzip from now on.Mcclary
Unfortunately the files I am fetching are in .Z format. Unless there is an automatic way of converting them to gzip format I have to stick with .Z format. Do you know any host which allows exec() ?Baluchistan
Well, practically any professional hoster is using suexec rather than the safemode workaround. Note that your zcat was a special version with .Z support; you might need to reinstall that or use uncompress -c $filename rather. Also remember escapeshellarg() here.Mcclary
I haven't used escapeshellarg() but php.net help file says "Escape a string to be used as a shell argument" but the issue is i think in order to use it i still need system() or exec() but my hosting has blocked both. Do you know any service provide who might not give me such nightmares?Baluchistan
@Mcclary how to use suexec? My hosting company told me that they have installed suexec but i can't still use exec() function so wondering how does it work now?Baluchistan
Has nothing do to with each other (suexec is a server setting, not a php function). Change your hoster.Mcclary
Dam! I can't find a host which is offering exec() i have tried searching for one even on google but no success so farBaluchistan
Just get a basic unmanaged VPS for $5/month and set up the stack yourself, and you won't have to worry about what the host disables.Brilliant
F
12

do this

echo ini_get("disable_functions");

to know if you are able to use one of the following:

system(); exec(); passthru(); shell_exec();

but if it's a shared hosting all the above are for sure blocked and you will have to find an alternative

Fennel answered 27/9, 2011 at 6:45 Comment(1)
show_source, system, shell_exec, passthru, exec, popen, proc_open, chmod, mkdir, chdir,allow_url_fopen,rmdirBaluchistan
W
5

.Z files are LZW compression. If you can't run shell commands on your host, you can use an LZW PHP library. Here are two:

Wist answered 28/9, 2011 at 13:1 Comment(0)
M
3
system($shell_command, $response_var);

So in your case:

system("zcat $filename", $output);
Minority answered 27/9, 2011 at 6:35 Comment(5)
i can almost bet that they blocked this and passthru() tooFennel
im sure they did too lol, just throwing out alternative methodsMinority
they have disabled system() tooBaluchistan
Yea figures, you need to call them and explain your situation. if they aren't interested in re-configuring anything for you, then you need to switch hosts.Minority
Well I tried calling them and didn't help since they aren't interested in re-configuring. Any recommendations as to which host might allow using exec() ?Baluchistan
M
0

In my case, disabled commands are

dl
sh2_exec
diskfreespace
disk_free_space
disk_total_space
escapeshellarg
escapeshellcmd
exec
highlight_file
link
lchgrp
lchown
passthru
pclose
popen
proc_close
proc_get_status
proc_nice
proc_open
proc_terminate
set_time_limit
shell_exec
show_source
symlink
system
mail
sendmail

So if one of those commands not blocked in your side, you may find a way to execute command.

Mannerheim answered 22/3, 2022 at 7:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.