Home >Backend Development >PHP Tutorial >ngx_lua implements restarting php

ngx_lua implements restarting php

WBOY
WBOYOriginal
2016-07-29 08:58:471030browse

nginx

<code>         location /reload {
             default_<span>type</span>  text/html;
             content_by_lua_file reload_php.lua;
         }</code>

lua

<code><span>local</span> args = ngx.req.get_query_args();
<span>local</span> uid = args[<span>"uid"</span>]
<span>local</span> key = args[<span>"key"</span>]
<span>local</span> uidmd5 = string.sub(ngx.md5(uid),<span>0</span>,<span>12</span>)

<span>if</span> key ~= uidmd5 then
     ngx.<span>say</span>(<span>"Hey man, you can't do this."</span>)
     ngx.<span>exit</span>(<span>200</span>)
<span>else</span><span>local</span> f = io.<span>open</span>(<span>"reload_access.log"</span> , <span>"a"</span>)
     <span>time</span> = os.date(<span>"<span>%c</span>"</span>,os.<span>time</span>())
     f:<span>write</span>(uid .. <span>" "</span> .. <span>time</span>)
     f:<span>close</span>()
     <span>local</span> command =<span>"sh reload_php.sh"</span>
     --<span>local</span> command =<span>"/bin/kill -USR2 `cat /var/run/php-fpm.pid`"</span>
     type = os.execute(command)
     <span>if</span> type == <span>0</span> then
          ngx.<span>print</span>(<span>"ok"</span>)
          ngx.<span>exit</span>(<span>200</span>)
     <span>else</span>
     ngx.<span>print</span>(<span>"error"</span>)
     f:<span>write</span>(<span>" error"</span>)
     f:<span>close</span>()
     ngx.<span>exit</span>(<span>200</span>)
     end
end</code>

shell

<code><span>#!/bin/bash</span><span>#</span><span>#reload php-fpm</span><span>#</span><span>#kill -USR2 `cat /var/run/php-fpm.pid`</span>
killall php-fpm
/php/sbin/php-fpm -c /etc/php.ini -y /php/etc/php-fpm.conf
<span>echo</span><span>" ok"</span> >> /reload_access.log</code>

I wrote this for fun, please correct me.

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the implementation of ngx_lua to restart PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn