开发者

Are there any alternatives to shell_exec and proc_open in PHP?

开发者 https://www.devze.com 2022-12-27 18:19 出处:网络
It seems like I can\'t use shell_exec or proc_open on my shared server. The message I get when I try to use it is:

It seems like I can't use shell_exec or proc_open on my shared server.

The message I get when I try to use it is:

Warning:开发者_Go百科 shell_exec() has been disabled for security reasons in /home/georgee/public_html/admin/email.php on line 4

Are there any alternatives to these functions?


I assume you want to use this for async processing, for instance sending eMails in a separate process (hence the error in email.php). If so, please check if cURL is enabled. You can trigger your scripts through an HTTP request without waiting for the response.

Further reading:

  • Asynchronous/parallel HTTP requests using PHP multi_curl
  • How to use curl_multi() without blocking
  • How do I make an asynchronous GET request in PHP?

If cURL is not available, try to use with non-blocking streams:

  • http://de.php.net/manual/en/function.stream-set-blocking.php
  • http://thethoughtlab.blogspot.com/2007/04/non-blocking-io-with-php-mio.html

For added security, consider using a self-defined API key, so the eMail sending URL cannot be triggered without permission. Pass this in as a GET or POST. You could also validate if the request came from the same server.


The only alternative is to not use shared hosting. They don't want you doing this for a reason.


Try using backtick operator

This answers seems to suggest these is not much you can do.


Just a follow up for people who need to use shared hosting. While I no longer recommend HostGator due to their sub-par support (resulting from their purchase by EIG), they do allow popen.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号