<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Carlos André Ferrari</title>
	<atom:link href="http://ferrari.eti.br/feed/" rel="self" type="application/rss+xml" />
	<link>http://ferrari.eti.br</link>
	<description>php, python, xhtml, html5, css, javascript, jquery, webstandards, linux, nginx</description>
	<lastBuildDate>Thu, 29 Jul 2010 10:05:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pegando a temperatura de qualquer cidade</title>
		<link>http://ferrari.eti.br/pegando-a-temperatura-de-qualquer-cidade/</link>
		<comments>http://ferrari.eti.br/pegando-a-temperatura-de-qualquer-cidade/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 09:36:38 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[codigo]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[temperatura]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=126</guid>
		<description><![CDATA[Me surgiu um trabalho aqui pelo qual preciso exibir a temperatura atual da cidade, e como estava com insônia decidi brincar um pouco e criar uma solução para isso, fui para o google e pesquisei por &#8220;Previsão do Tempo&#8220;, me surgiram alguns resultados, porém, gostei mais do UOL.
Depois disso foi correr para a criação do [...]]]></description>
			<content:encoded><![CDATA[<p>Me surgiu um trabalho aqui pelo qual preciso exibir a <strong>temperatura</strong> atual da cidade, e como estava com insônia decidi brincar um pouco e criar uma solução para isso, fui para o google e pesquisei por &#8220;<strong>Previsão do Tempo</strong>&#8220;, me surgiram alguns resultados, porém, gostei mais do <a href="http://tempoagora.uol.com.br/previsaodotempo.html/brasil/Palmas-TO/">UOL</a>.</p>
<p>Depois disso foi correr para a criação do script para ler o HTML e retornar um objeto contendo as informações da temperatura no momento, segue o código escrito em <strong>php</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> loadTemp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cidade</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'Palmas-TO'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// variavel para dados de retorno</span>
	<span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;http://tempoagora.uol.com.br/previsaodotempo.html/brasil/<span style="color: #006699; font-weight: bold;">$cidade</span>/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// carrega o html do tempoagora</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Pegamos apenas a parte que interessa do html</span>
	<span style="color: #000088;">$iniflag</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;!-- Insere dados Atuais de AeroPortos ou Est. Meteorologica --&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$fimflag</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;!-- FIM Insere dados Atuais de AeroPortos ou Est. Meteorologica --&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ini</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$iniflag</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iniflag</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$fim</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fimflag</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ini</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ini</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fim</span><span style="color: #339933;">-</span><span style="color: #000088;">$ini</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// pegamos a url do icone</span>
	<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@&lt;img src=&quot;/(imagens/icones/[a-zA-Z\-]+.gif)&quot;@'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mat</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'icone'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://tempoagora.uol.com.br/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$mat</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Limpa o código html</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;nbsp;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// quebra o que sobrou em um vetor</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// limpa espaços e linhas em branco</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$v</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #339933;">===</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// pega horário da verificação</span>
	<span style="color: #000088;">$lin</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@[0-9]{1,2}:[0-9]{1,2}@'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lin</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mat</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'verificado'</span><span style="color: #009900;">&#93;</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$mat</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// pega insidência de nuvens</span>
	<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nuvens'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// define nomes melhores para as próximas propriedades</span>
	<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'temperatura'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sensacao'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'vento'</span><span style="color: #339933;">,</span> 
			<span style="color: #0000ff;">'pressao'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'umidade'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'visibilidade'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// reseta as chaves do vetor</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_unique</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// percorre chaves impares e aplica as propriedades definidas acima</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">11</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">=</span><span style="color: #000088;">$x</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keys</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// retorna os dados como um objeto</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Analisando o site deles, notei que a <strong>temperatura</strong> é atualizada de hora em hora, então a melhor forma de utilizar essa solução é utilizando o <strong>crontab</strong>, que executa a cada hora, eu escolhi executar no quinto minuto de cada hora cheia (5:05, 6:05, etc).</p>
<p>segue o código <strong>php</strong> que o <strong>crontab</strong> executa:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'loadTemp.php'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// define nome do arquivo de cache</span>
<span style="color: #000088;">$cache_file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sys_get_temp_dir</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/temp'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// carrega a temperatura</span>
<span style="color: #000088;">$temp</span> <span style="color: #339933;">=</span> loadTemp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// salva em cache</span>
<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_file</span><span style="color: #339933;">,</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>E para exibir no sistema eu fiz uma funçãozinha:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> temp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$cache_file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sys_get_temp_dir</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/temp'</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// se o cache existe, retorna o objeto</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// senão cria o cache e retorna =)</span>
	<span style="color: #000088;">$temp</span> <span style="color: #339933;">=</span> loadTemp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_file</span><span style="color: #339933;">,</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>depois, no local específico, ficou algo mais ou menos assim:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$temp</span> <span style="color: #339933;">=</span> temp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">icone</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; alt=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nuvens</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;span&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">temperatura</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> (&lt;a rel=&quot;external&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;saiba mais&lt;/a&gt;)&lt;/span&gt;</pre></div></div>

<p>Minha forma de pagar por esse uso é manter um link para o <a href="http://tempoagora.uol.com.br/">Tempoagora</a>, o que é bastante interessante, pois meu visitante pode querer obter mais informações</p>
<p>É isso ai, abraço a todos</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/pegando-a-temperatura-de-qualquer-cidade/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Classe, WebService e RSS para rastreamento de encomendas nos Correios em PHP</title>
		<link>http://ferrari.eti.br/classe-api-webservice-para-rastreamento-de-encomendas-nos-correios-em-php/</link>
		<comments>http://ferrari.eti.br/classe-api-webservice-para-rastreamento-de-encomendas-nos-correios-em-php/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 10:25:32 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[github]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[opensource]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=117</guid>
		<description><![CDATA[Olá, depois de meses sem escrever estou voltando com uma classe muito útil e simples que nunca vi em lugar nenhum. É uma classe para rastrear encomendas nos correios que eu escrevi em PHP, que retorna um vetor com cada modificação de status lá.
Vamos direto ao ponto, confira o exemplo:
http://ferrari.eti.br/correios/samples/class.php
E para deixar a brincadeira mais [...]]]></description>
			<content:encoded><![CDATA[<p>Olá, depois de meses sem escrever estou voltando com uma <strong>classe</strong> muito útil e simples que nunca vi em lugar nenhum. É uma classe para rastrear encomendas nos <strong>correios</strong> que eu escrevi em <strong>PHP</strong>, que retorna um vetor com cada modificação de status lá.</p>
<p>Vamos direto ao ponto, confira o exemplo:</p>
<p><a href="http://ferrari.eti.br/correios/samples/class.php">http://ferrari.eti.br/correios/samples/class.php</a></p>
<p>E para deixar a brincadeira mais divertida, fiz também um <strong>webservice</strong> com suporte a <strong>Json</strong> (padrão), <strong>phpserialize</strong>, <strong>XML</strong> e um modo dump, para visualização:</p>
<p><a href="http://ferrari.eti.br/correios/webservice/?q=PB151832535BR">http://ferrari.eti.br/correios/webservice/?q=PB151832535BR</a><br />
<a href="http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=dump">http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=dump</a><br />
<a href="http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=serial">http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=serial</a><br />
<a href="http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=xml">http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=xml</a><br />
e claro, para quem usa <strong>Ajax</strong>:<br />
<a href="http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;callback=minhaFuncJs">http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;callback=minhaFuncJs</a></p>
<p>Disponibilizei tanto a classe quanto o código do webservice (que tem suporte a <strong>caching</strong>!) &#8220;de grátis&#8221; e com licença BSD no <strong>github</strong>:</p>
<p><a href="http://github.com/caferrari/correios/">http://github.com/caferrari/correios/</a></p>
<p><strong>*UPDATE* </strong>Adicionado um gerador de RSS, assim é possível usar o proprio agregador para fazer o tracking!<strong></strong></p>
<p><a href="http://ferrari.eti.br/correios/rss/?PB151832535BR">http://ferrari.eti.br/correios/rss/?PB151832535BR</a></p>
<p>e em homenagem aos atendentes de telemarketing: Estarei esperando forks e colaborações para a classe, além de comentários!.</p>
<p>Até a próxima.</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/classe-api-webservice-para-rastreamento-de-encomendas-nos-correios-em-php/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>PHP 5.3, PHP-FPM, XCache, Nginx no Debian Lenny &#8211; Performance extrema</title>
		<link>http://ferrari.eti.br/php-5-3-php-fpm-xcache-nginx-no-debian-lenny-performance-extrema/</link>
		<comments>http://ferrari.eti.br/php-5-3-php-fpm-xcache-nginx-no-debian-lenny-performance-extrema/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 14:36:08 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[webserver]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xcache]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=112</guid>
		<description><![CDATA[Neste post vou exemplificar os passos para configurar um Webserver que consome poucos recursos e é extremamente rápido no Debian Lenny.
PHP-FPM: é um gerenciador de processos CGI do php, similar ao Phpcgi, porém com várias vantagens como:

Gerenciador de Processos muito eficiente, com capacidade de parar e iniciar seus deamons caso necessário
Possibilidade de Iniciar processos com [...]]]></description>
			<content:encoded><![CDATA[<p>Neste post vou exemplificar os passos para configurar um Webserver que consome poucos recursos e é extremamente rápido no <a href="http://www.debian.org/">Debian Lenny</a>.</p>
<p><a href="http://php-fpm.org/">PHP-FPM</a>: é um gerenciador de processos CGI do php, similar ao Phpcgi, porém com várias vantagens como:</p>
<ul>
<li>Gerenciador de Processos muito eficiente, com capacidade de parar e iniciar seus <a href="http://en.wikipedia.org/wiki/Daemon">deamons</a> caso necessário</li>
<li>Possibilidade de Iniciar processos com usuários diferentes e com arquivos php.ini diferentes</li>
<li>Uploads otimizados</li>
<li>Capacidade de reinicializar processos caso ocorra algum problema</li>
<li>Escalabilidade de processos, ele pode criar mais processos de acordo com a demanda</li>
<li>e muito mais.</li>
</ul>
<p><a href="http://xcache.lighttpd.net/">XCache</a>: é um gerenciador de cache, que armazena os scripts php em <a href="http://en.wikipedia.org/wiki/Opcode">opcode</a> para uso futuro, é extremamente rápido e muito usado no mundo em servidores com alta demanda.</p>
<p><a href="http://nginx.org">Nginx</a>: Conheci este webserver lendo o <a href="http://www.boo-box.com/blog/br/2009/nova-infraestrutura-de-servidores-web-do-sistema-boo-box/">blog da boo-box</a>, ele é um Servidor web e proxy reverso extremamente veloz e que vem ganhando mercado nos últimos meses devido a sua facilidade de uso e capacidade de carga.</p>
<p style="text-align: center;"><a href="http://royal.pingdom.com/2010/01/22/internet-2009-in-numbers/"><img class="aligncenter" title="Market Share de navegadores no final de 2009" src="http://farm5.static.flickr.com/4022/4295546152_b8e094e8cc_o.png" alt="Market Share de navegadores no final de 2009" width="580" height="300" /></a></p>
<p>Para agilizar a configuração, vamos usar alguns pacotes (php5.3, php-fpm) pré compilados e mantidos <a href="http://www.dotdeb.org/">www.dotdeb.org.</a> os testes que eu realzei usando estes pacotes tiveram um ganho de performance enorme.</p>
<h3>Instalação:</h3>
<p>Vamos começar adicionado os repositórios do dotdeb no /etc/apt/sources.list:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">deb http:<span style="color: #000000; font-weight: bold;">//</span>php53.dotdeb.org stable all
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>php53.dotdeb.org stable all</pre></div></div>

<p>Vamos instalar os pacotes e algumas dependências para o nginx:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> update
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-fpm php5-xcache php5-gd php5-curl \
php5-mysql php5-pgsql libssl-dev libpcre3-dev build-essential <span style="color: #660033;">-y</span></pre></div></div>

<p>Agora temos o php instalado, vamos compilar o nginx:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> src
<span style="color: #7a0874; font-weight: bold;">cd</span> src
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>nginx.org<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>nginx-0.7.64.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxvf</span> nginx-0.7.64.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> nginx-0.7.64
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx <span style="color: #660033;">--user</span>=www-data <span style="color: #660033;">--group</span>=www-data \
    --without-mail_pop3_module --without-mail_imap_module \
    --without-mail_smtp_module --with-http_stub_status_module \
    --with-http_ssl_module <span style="color: #660033;">--http-log-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>access.log \
    <span style="color: #660033;">--conf-path</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>nginx.conf  <span style="color: #660033;">--pid-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>nginx.pid
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Se tudo ocorreu bem, você já tem o nginx instalado, vamos apenas coloca-lo para inicializar automáticamente, crie o arquivo /etc/init.d/nginx e coloque o conteúdo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### BEGIN INIT INFO</span>
<span style="color: #666666; font-style: italic;"># Provides:          nginx</span>
<span style="color: #666666; font-style: italic;"># Required-Start:    $all</span>
<span style="color: #666666; font-style: italic;"># Required-Stop:     $all</span>
<span style="color: #666666; font-style: italic;"># Default-Start:     2 3 4 5</span>
<span style="color: #666666; font-style: italic;"># Default-Stop:      0 1 6</span>
<span style="color: #666666; font-style: italic;"># Short-Description: starts the nginx web server</span>
<span style="color: #666666; font-style: italic;"># Description:       starts nginx using start-stop-daemon</span>
<span style="color: #666666; font-style: italic;">### END INIT INFO</span>
&nbsp;
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span>
<span style="color: #007800;">DAEMON</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>nginx
<span style="color: #007800;">NAME</span>=nginx
<span style="color: #007800;">DESC</span>=nginx
&nbsp;
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-x</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Include nginx defaults if available</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>default<span style="color: #000000; font-weight: bold;">/</span>nginx <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
        . <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>default<span style="color: #000000; font-weight: bold;">/</span>nginx
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-e</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
  start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting <span style="color: #007800;">$DESC</span>: &quot;</span>
        start-stop-daemon <span style="color: #660033;">--start</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid \
                <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$DAEMON_OPTS</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping <span style="color: #007800;">$DESC</span>: &quot;</span>
        start-stop-daemon <span style="color: #660033;">--stop</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid \
                <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  restart<span style="color: #000000; font-weight: bold;">|</span>force-reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Restarting <span style="color: #007800;">$DESC</span>: &quot;</span>
        start-stop-daemon <span style="color: #660033;">--stop</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> \
                <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
        start-stop-daemon <span style="color: #660033;">--start</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> \
                <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$DAEMON_OPTS</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Reloading <span style="color: #007800;">$DESC</span> configuration: &quot;</span>
        start-stop-daemon <span style="color: #660033;">--stop</span> <span style="color: #660033;">--signal</span> HUP <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid \
            <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  configtest<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Testing <span style="color: #007800;">$DESC</span> configuration: &quot;</span>
        <span style="color: #000000; font-weight: bold;">if</span> nginx <span style="color: #660033;">-t</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">then</span>
          <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
          <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$?</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: <span style="color: #007800;">$NAME</span> {start|stop|restart|reload|force-reload|configtest}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>depois vamos torna-lo executável e atualizar o rc.d:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx
update-rc.d nginx defaults</pre></div></div>

<p>Com isso o processo de instalação está concluído, vamos configurar!</p>
<h3>Configuração do XCache</h3>
<p>Coloque a seguinte configuração no arquivo /etc/php5/fpm/conf.d/xcache.ini:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">; configuration for php xcache module</span>
<span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">xcache.so</span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>xcache.admin<span style="">&#93;</span></span>
xcache.admin.user <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;secom&quot;</span>
<span style="color: #666666; font-style: italic;">; xcache.admin.pass = md5($your_password)</span>
xcache.admin.pass <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;&quot;</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>xcache<span style="">&#93;</span></span>
<span style="color: #666666; font-style: italic;">; ini only settings, all the values here is default unless explained</span>
<span style="color: #666666; font-style: italic;">; select low level shm/allocator scheme implemenation</span>
xcache.shm_scheme <span style="color: #000066; font-weight:bold;">=</span>        <span style="color: #933;">&quot;mmap&quot;</span>
<span style="color: #666666; font-style: italic;">; to disable: xcache.size=0</span>
<span style="color: #666666; font-style: italic;">; to enable : xcache.size=64M etc (any size &gt; 0) and your system mmap allows</span>
xcache.size  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">                64M</span>
<span style="color: #666666; font-style: italic;">; set to cpu count (cat /proc/cpuinfo |grep -c processor)</span>
xcache.count <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">                 1</span>
<span style="color: #666666; font-style: italic;">; just a hash hints, you can always store count(items) &gt; slots</span>
xcache.slots <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">                8K</span>
<span style="color: #666666; font-style: italic;">; ttl of the cache item, 0=forever</span>
xcache.ttl   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">                 0</span>
<span style="color: #666666; font-style: italic;">; interval of gc scanning expired items, 0=no scan, other values is in seconds</span>
xcache.gc_interval <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">           0</span>
<span style="color: #666666; font-style: italic;">; same as aboves but for variable cache</span>
xcache.var_size  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">            64M</span>
xcache.var_count <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">             1</span>
xcache.var_slots <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">            8K</span>
<span style="color: #666666; font-style: italic;">; default ttl</span>
xcache.var_ttl   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">             0</span>
xcache.var_maxttl   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">          0</span>
xcache.var_gc_interval <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">     300</span>
xcache.test <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">                Off</span>
<span style="color: #666666; font-style: italic;">; N/A for /dev/zero</span>
xcache.readonly_protection <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> Off</span>
<span style="color: #666666; font-style: italic;">; for *nix, xcache.mmap_path is a file path, not directory.</span>
<span style="color: #666666; font-style: italic;">; Use something like &quot;/tmp/xcache&quot; if you want to turn on ReadonlyProtection</span>
<span style="color: #666666; font-style: italic;">; 2 group of php won't share the same /tmp/xcache</span>
<span style="color: #666666; font-style: italic;">; for win32, xcache.mmap_path=anonymous map name, not file path</span>
xcache.mmap_path <span style="color: #000066; font-weight:bold;">=</span>    <span style="color: #933;">&quot;/dev/zero&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; leave it blank(disabled) or &quot;/tmp/phpcore/&quot;</span>
<span style="color: #666666; font-style: italic;">; make sure it's writable by php (without checking open_basedir)</span>
xcache.coredump_directory <span style="color: #000066; font-weight:bold;">=</span>   <span style="color: #933;">&quot;&quot;</span>
<span style="color: #666666; font-style: italic;">; per request settings</span>
xcache.cacher <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">               On</span>
xcache.stat   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">               On</span>
xcache.optimizer <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">            On</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>xcache.coverager<span style="">&#93;</span></span>
<span style="color: #666666; font-style: italic;">; per request settings</span>
<span style="color: #666666; font-style: italic;">; enable coverage data collecting for xcache.coveragedump_directory and xcache_coverager_start/stop/get/clean() functions (will hurt executing performance)</span>
xcache.coverager <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">          Off</span>
<span style="color: #666666; font-style: italic;">; ini only settings</span>
<span style="color: #666666; font-style: italic;">; make sure it's readable (care open_basedir) by coverage viewer script</span>
<span style="color: #666666; font-style: italic;">; requires xcache.coverager=On</span>
xcache.coveragedump_directory <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;&quot;</span></pre></div></div>

<h3>Configuração do Nginx</h3>
<p>Edite o arquivo em /etc/nginx/nginx.conf:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user  www-data;
&nbsp;
<span style="color: #666666; font-style: italic;">#Coloque quantos processos simultaneos, o ideal é um para cada nucleo do sistema:</span>
worker_processes  <span style="color: #000000;">4</span>;
&nbsp;
error_log  <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>error.log;
&nbsp;
events <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #666666; font-style: italic;"># numero de conexões simultaneas por worker</span>
    worker_connections  <span style="color: #000000;">1024</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
http <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    include       mime.types;
    default_type  application<span style="color: #000000; font-weight: bold;">/</span>octet-stream;
&nbsp;
    access_log  <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>access.log;
    sendfile        on;
    <span style="color: #666666; font-style: italic;"># isso é interessante, dá um ganho enorme na navegação, e o nginx aguenta tranquilamente</span>
    keepalive_timeout  <span style="color: #000000;">60</span>;
    tcp_nodelay        on;
&nbsp;
    <span style="color: #666666; font-style: italic;">## Compressão</span>
    <span style="color: #c20cb9; font-weight: bold;">gzip</span> on;
    gzip_http_version <span style="color: #000000;">1.0</span>;
    gzip_comp_level <span style="color: #000000;">2</span>;
    gzip_proxied any;
    gzip_min_length  <span style="color: #000000;">1100</span>;
    gzip_buffers <span style="color: #000000;">16</span> 8k;
    <span style="color: #666666; font-style: italic;"># mime types para zipar e adicionar header de cache</span>
    gzip_types text<span style="color: #000000; font-weight: bold;">/</span>plain text<span style="color: #000000; font-weight: bold;">/</span>css application<span style="color: #000000; font-weight: bold;">/</span>x-javascript text<span style="color: #000000; font-weight: bold;">/</span>xml application<span style="color: #000000; font-weight: bold;">/</span>xml application<span style="color: #000000; font-weight: bold;">/</span>xml+rss text<span style="color: #000000; font-weight: bold;">/</span>javascript image<span style="color: #000000; font-weight: bold;">/</span>gif image<span style="color: #000000; font-weight: bold;">/</span>jpeg image<span style="color: #000000; font-weight: bold;">/</span>png;
    <span style="color: #666666; font-style: italic;"># Desabilita compressão em algumas versões do IE6</span>
    gzip_disable <span style="color: #ff0000;">&quot;MSIE [1-6].(?!.*SV1)&quot;</span>;
    <span style="color: #666666; font-style: italic;"># Impede que servidores proxy mandem versões em gzip do arquivo para os IE6</span>
    gzip_vary on;
&nbsp;
    server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	root  <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>;
	server_name     localhost;
	listen          <span style="color: #000000;">80</span>;
	location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		index  index.php index.html index.htm;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">#error_page  404  /404.html;</span>
	<span style="color: #666666; font-style: italic;"># redirect server error pages to the static page /50x.html</span>
	error_page   <span style="color: #000000;">500</span> <span style="color: #000000;">502</span> <span style="color: #000000;">503</span> <span style="color: #000000;">504</span>  <span style="color: #000000; font-weight: bold;">/</span>50x.html;
	location = <span style="color: #000000; font-weight: bold;">/</span>50x.html <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		root   <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>nginx-default;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># Joga requisições para arquivos .php para o php-fpm</span>
	location ~ \.php$ <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		fastcgi_pass   127.0.0.1:<span style="color: #000000;">9000</span>;
		fastcgi_index  index.php;
		include fastcgi_params;
        	fastcgi_param SCRIPT_FILENAME <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$fastcgi_script_name</span>;
        	fastcgi_param SERVER_NAME <span style="color: #007800;">$http_host</span>;
        	fastcgi_ignore_client_abort on;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<h3>Configuração do php-fpm</h3>
<p>Edite o arquivo: /etc/php5/fpm/php5-fpm.conf e faça os ajustes que você achar interessante, aqui eu só aumento os max_childrens (Numero de clientes CGI) de 5 para 50, esta configuração depende do seu hardware.</p>
<h3>Configuração do Logrotate</h3>
<p>Vamos configurar agora o logrotate para não enchermos os discos com logs do nginx, edite o arquivo /etc/logrotate.d/nginx:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/*</span>.log <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        daily
        missingok
        rotate <span style="color: #000000;">7</span>
        compress
        delaycompress
        notifempty
        create <span style="color: #000000;">640</span> root adm
        sharedscripts
        postrotate
                <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>nginx.pid <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-USR1</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>nginx.p$
        endscript
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<h3>Finalizando</h3>
<p>Agora que está tudo configurado, vamos reinicalizar os serviços:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>php5-fpm restart
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx restart</pre></div></div>

<p>crie um arquivo /var/www/index.php e vamos testar o php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
e acesse<span style="color: #339933;">:</span> http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//ip_do_servidor/</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/php-5-3-php-fpm-xcache-nginx-no-debian-lenny-performance-extrema/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>GVT, Vivendi, Internet, TV Digital e o Futuro</title>
		<link>http://ferrari.eti.br/gvt-vivendi-internet-tv-digital-e-o-futuro/</link>
		<comments>http://ferrari.eti.br/gvt-vivendi-internet-tv-digital-e-o-futuro/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 13:37:10 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[diversos]]></category>
		<category><![CDATA[inovação]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[tendências]]></category>
		<category><![CDATA[tv digital]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=106</guid>
		<description><![CDATA[Nos últimos meses estou acompanhando notícias sobre a venda da GVT, no inicio a Vivendi fez uma oferta muito boa para a aquisição, porém a Telecômica Telefônica apareceu com uma oferta bem maior e quando tudo parecia perdido foi anunciada a compra de 57,5% das ações da GVT pela Vivendi!
A GVT é conhecida como a [...]]]></description>
			<content:encoded><![CDATA[<p>Nos últimos meses estou acompanhando notícias sobre a venda da <a href="http://pt.wikipedia.org/wiki/Global_Village_Telecom">GVT</a>, no inicio a <a href="http://pt.wikipedia.org/wiki/Vivendi">Vivendi</a> fez uma oferta muito boa para a aquisição, porém a <del>Telecômica</del> Telefônica apareceu com uma oferta bem maior e quando tudo parecia perdido foi anunciada a <a href="http://forumpcs.com.br/viewtopic.php?t=261188">compra de 57,5% das ações da GVT pela Vivendi</a>!</p>
<p>A GVT é conhecida como a melhor (realmente muito melhor) operadora de telefônia, que nasceu e atua no Brasil, e ela é melhor em todos os aspectos (atendimento, preço, qualidade de serviço e qualidade de banda larga) enquanto a <a href="http://www.reclameaqui.com.br/indices/1956/telefonica-speedy">Telefônica</a> compete com a <a href="http://www.reclameaqui.com.br/indices/?id=1492">Oi</a> pelo maior numero de clientes insatisfeitos.</p>
<p>A Vivendi é uma empresa francesa que atua no setor de mídia e comunicação com atividades na música, televisão, cinema, editoração, telecomunicações e Internet. (por: Wikipedia)</p>
<div id="attachment_107" class="wp-caption aligncenter" style="width: 610px"><img class="size-full wp-image-107" title="vivendi" src="http://ferrari.eti.br/wp-content/uploads/2009/11/vivendi.jpg" alt="Areas de atuação da Vivendi" width="600" height="357" /><p class="wp-caption-text">Areas de atuação da Vivendi</p></div>
<p>Bom, mas o que isso significa&#8230;</p>
<p>Vamos considerar os seguintes pontos:</p>
<ul>
<li>Governo investindo em inclusão digital</li>
<li>Qualidade dos serviços e atendimento da GVT</li>
<li>O know-how em mídias e o dinheiro da Vivendi</li>
</ul>
<p>E juntamos isso com o fato de que a mídia da forma que conhecemos está definhando devido a Internet (RSS, Twitter, Orkut, Facebook, etc).</p>
<p>Com apenas isso já é possível se concluir o óbvio. A Vivendi está vindo para, além de nos prover acesso a internet com qualidade e chutar a Oi e Telefônica de vez, nos prover um serviço que pode em pouco tempo engolir também a nossa TV Digital. <a href="http://www.iptv-news.com/iptv_news/september_09_3/vivendi_plans_iptv_for_brazils_gvt">Ela vem para criar aqui um sistema de IPTV</a></p>
<p>Se pararmos para analisar, a TV Digital do mundo todo irá evoluir para <a href="http://pt.wikipedia.org/wiki/IPTV">IPTV</a>, pois, todas as qualidades da TV Digital (<a href="http://pt.wikipedia.org/wiki/1080p">FullHD</a>, <a href="http://pt.wikipedia.org/wiki/Som_surround">Som Surround</a> e <a href="http://pt.wikipedia.org/wiki/Interatividade">Interatividade</a>) podem ser superadas pela Internet.</p>
<p>Daí pega outro ponto: Infraestrutura, porém, para vocês terem uma ideia, no Japão um link de 100Mb por <a href="http://pt.wikipedia.org/wiki/Fibra_%C3%B3ptica">fibra ótica</a> custa o equivalente a 60 reais por mês. Mas acredito que a Vivendi tem cacife suficiente para engolir <span style="text-decoration: line-through;">os lixos</span> as empresas em que somos obrigados a depender e pagar 100 reais por meros 2mb de banda com <a href="http://conexaoto.com.br/noticia/operadora-oi-pode-estar-praticando--traffic-shaping-no-tocantins/6726">Traffic Shaping</a> e finalmente nos prover um serviço de “primeiro mundo”.</p>
<p>As questões que ficam são:</p>
<p>Irá no final das contas a TV digital sobreviver? Ou veremos nossas mães e irmãs assistindo as novelas e discutindo com amigas em tempo real pela TV ou pelo Computador?</p>
<p>Após escrever essa pergunta me surgiram outras questões:</p>
<ul>
<li>Quanto tempo a <a href="http://pt.wikipedia.org/wiki/Televis%C3%A3o_digital_no_Brasil">TV Digital Brasileira</a> irá sobreviver?</li>
<li>Quanto tempo vai levar até a Globo, Record ou outra emissora começar a transmitir suas programações ao vivo e em tempo real pela internet?</li>
<li>Quanto tempo irá levar para todas as <a href="http://barbusci.com.br/blog2/?p=9">mídias de massa</a> se <a href="http://mundoconectado.blogspot.com/2006/08/mas-afinal-o-que-convergncia-digital.html">convergirem</a> na Internet?</li>
</ul>
<p>No final de tudo uma certeza eu tenho: Quem resistir vai ser engolido.</p>
<p>Até!</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/gvt-vivendi-internet-tv-digital-e-o-futuro/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Trabalhando em Grupo em um mesmo branch no git</title>
		<link>http://ferrari.eti.br/trabalhando-em-grupo-em-um-mesmo-branch-no-gi/</link>
		<comments>http://ferrari.eti.br/trabalhando-em-grupo-em-um-mesmo-branch-no-gi/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 19:58:29 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=96</guid>
		<description><![CDATA[Problema: Trabalhar em grupo em um branch que não seja o master usando git.
Solução:
Considerando que o repositório já está ok, e você já está conectado no remote:
Aqui estão os passos para criar o branch que a equipe vai trabalhar

# criar o branch
git checkout -b meu_branch
# enviar o branch para a origem
git push origin meu_branch
# vamos [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problema:</strong> Trabalhar em grupo em um branch que não seja o master usando git.</p>
<p><strong>Solução:</strong><br />
Considerando que o repositório já está ok, e você já está conectado no remote:</p>
<p>Aqui estão os passos para criar o branch que a equipe vai trabalhar</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># criar o branch</span>
git checkout <span style="color: #660033;">-b</span> meu_branch
<span style="color: #666666; font-style: italic;"># enviar o branch para a origem</span>
git push origin meu_branch
<span style="color: #666666; font-style: italic;"># vamos apagar esse branch local agora</span>
git checkout master
git branch <span style="color: #660033;">-D</span> meu_branch</pre></div></div>

<p>Agora cada um que vai trabalhar com este branch pode adicioná-lo assim:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git checkout <span style="color: #660033;">--track</span> <span style="color: #660033;">-b</span> meu_branch origin<span style="color: #000000; font-weight: bold;">/</span>meu_branch</pre></div></div>

<p>Agora todo mundo da equipe pode trabalhar no &#8220;meu_branch&#8221; como se estivesse no master.</p>
<p>e para excluir o branch da origem faça:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git push origin :meu_branch</pre></div></div>

<p>Até a proxima</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/trabalhando-em-grupo-em-um-mesmo-branch-no-gi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Backup automático do postgres + rsync para outra máquina</title>
		<link>http://ferrari.eti.br/backup-automatico-do-postgres-usando-rsync/</link>
		<comments>http://ferrari.eti.br/backup-automatico-do-postgres-usando-rsync/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 19:16:33 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=91</guid>
		<description><![CDATA[Aqui vou exemplificar a solução que usamos para fazer backup diário dos nossos bancos de dados, este backup é armazenado em um servidor fora do país. para fazer a sincronia, usamos o rsync.
1) Configurando login automático via chaves digitais no nosso servidor de armazenamento
Primeiro você tem que gerar as chaves no seu servidor de banco, [...]]]></description>
			<content:encoded><![CDATA[<p>Aqui vou exemplificar a solução que usamos para fazer backup diário dos nossos bancos de dados, este backup é armazenado em um servidor fora do país. para fazer a sincronia, usamos o <a href="http://samba.anu.edu.au/rsync/">rsync</a>.</p>
<h2>1) Configurando login automático via chaves digitais no nosso servidor de armazenamento</h2>
<p>Primeiro você tem que gerar as chaves no seu servidor de banco, com o usuário do banco de dados, no meu caso é o usuário &#8220;postgres&#8221;.</p>
<p>Você será perguntado por uma senha, deixe em branco e confirme:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">su</span> postgres
$ <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> dsa</pre></div></div>

<p>Agora você terá sua chave, copie-a para seu servidor que irá armazenar o backup</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">scp</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_dsa.pub user<span style="color: #000000; font-weight: bold;">@</span>server_bkp:~<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Agora acesse seu servidor via ssh e adicione a chave pública na lista de chaves autorizadas do ssh</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> user<span style="color: #000000; font-weight: bold;">@</span>server_bkp
$ <span style="color: #c20cb9; font-weight: bold;">cat</span> ~<span style="color: #000000; font-weight: bold;">/</span>id_dsa.pub <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys</pre></div></div>

<p>Volte para o seu servidor de banco no usuario do postgres e teste:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> user<span style="color: #000000; font-weight: bold;">@</span>server_bkp</pre></div></div>

<p>Se você conseguiu acessar o server de backup sem digitar senha, continue no passo 2, senão, de uma revisada. qualquer dúvida comente!.</p>
<h2>2) Instalando o rsync e script de backup</h2>
<p>Para instalar o rsync no debian é bem simples:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> rsync</pre></div></div>

<p>No nosso banco de dados os backups são feitos diariamente as 19 horas, e usamos a pasta /backup para armazena-los:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>backup
$ <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>backup.sh
$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>backup.sh
$ <span style="color: #c20cb9; font-weight: bold;">chown</span> postgres:postgres <span style="color: #000000; font-weight: bold;">/</span>backup <span style="color: #660033;">-R</span></pre></div></div>

<p>Agora, edite o arquivo backup.sh e coloque o conteúdo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">PASTA</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">DATA</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">DIA</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$PASTA</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$PASTA</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DIA</span>
&nbsp;
<span style="color: #007800;">LIST</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>psql <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $1}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-vE</span> <span style="color: #ff0000;">'^-|^\(|^List|^N[o|a]me|template[0|1]'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">for</span> d <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$LIST</span>
<span style="color: #000000; font-weight: bold;">do</span>
        pg_dump <span style="color: #660033;">-i</span> <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-p</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-F</span> t <span style="color: #660033;">-b</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;/backup/<span style="color: #007800;">$DATA</span>-<span style="color: #007800;">$d</span>.backup&quot;</span> <span style="color: #007800;">$d</span>
        <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zcf</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$PASTA</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DIA</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DATA</span>-<span style="color: #007800;">$d</span>.tar.gz <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DATA</span>-<span style="color: #007800;">$d</span>.backup
        <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DATA</span>-<span style="color: #007800;">$d</span>.backup
        <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rsync <span style="color: #660033;">-avzh</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--progress</span> <span style="color: #660033;">--update</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span> user<span style="color: #000000; font-weight: bold;">@</span>server_bkp:~<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>faça um teste e rode o script com o user do postgres:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">su</span> postgres
$ <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>backup.sh</pre></div></div>

<p>Se tudo ocorrer bem, é só adicionar no crontab para executar quando você quiser:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">su</span>
$ pico <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>crontab</pre></div></div>

<p>e adicionar:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span> <span style="color: #000000;">19</span>    <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>   postgres    <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>backup.sh</pre></div></div>

<p>Reinicie o cron e o backup será feito todos os dias as 19 horas.</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/backup-automatico-do-postgres-usando-rsync/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>nginx &#8211; webserver, proxy reverso e perfeito!</title>
		<link>http://ferrari.eti.br/nginx-webserver-proxy-reverso-e-perfeito/</link>
		<comments>http://ferrari.eti.br/nginx-webserver-proxy-reverso-e-perfeito/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 13:00:25 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=85</guid>
		<description><![CDATA[Nosso departamento é responsável por manter a identidade visual dos sites do Governo do Estado e ainda fazemos os sites dos orgãos que não possuem um.
No trabalho sempre tivemos um constante problema para hospedar nossos sites: hardware!. Contamos hoje com dois incríveis servidores IBM Pentium4 3Ghz com 2gb de memória e HDs scsi, um para [...]]]></description>
			<content:encoded><![CDATA[<p>Nosso <a href="http://web.secom.to.gov.br">departamento</a> é responsável por manter a identidade visual dos sites do <a href="http://to.gov.br">Governo do Estado</a> e ainda fazemos os sites dos orgãos que não possuem um.</p>
<p>No trabalho sempre tivemos um constante problema para hospedar nossos sites: hardware!. Contamos hoje com dois incríveis servidores IBM Pentium4 3Ghz com 2gb de memória e HDs scsi, um para hospedar mais de 40 sites e o outro onde fica postgres com os bancos de dados desses sites.</p>
<p>Ultimamente nosso problema tem crescido bastante, pois, a demanda por sites aumentou e ao mesmo tempo o número de visitas veio aumentando e, como não conseguimos de forma alguma (até agora) investimento em equipamento novo estavamos chegando em uma situação crítica, nosso servidor começava a <del datetime="2009-10-15T12:28:06+00:00">sentar</del> morrer com 200 conexões simultaneas!</p>
<p>Lembrei-me de um <a href="http://www.boo-box.com/blog/br/2009/a-infraestrutura-de-servidores-web-do-sistema-boo-box/">post do boo-box</a> onde vi um servidor web chamado <a href="http://nginx.net">nginx</a> (lê-se engineX) e decidi pesquisar mais e fazer testes em casa onde rodando um servidor e servindo uma página php com um usleep de meio segundo consegui mais de 2000 conexões simultaneas! uau!..</p>
<p style="text-align: center;"><img class="aligncenter" title="nginx_performance" src="../wp-content/uploads/2009/10/nginx_performance.jpg" alt="nginx_performance" width="500" height="331" /></p>
<p>Na segunda feira seguinte, sem pensar muito, fui para o nosso servidor de produção e apliquei a seguinte política de funcionamento:</p>
<ul>
<li>nginx recebe todas as conexões pela porta 80</li>
<li>nginx faz proxy para o apache (que roda em outra porta) se a solicitação for para uma página php</li>
<li>nginx resolve sozinho usando php-cgi caso a requisição seja para:
<ul>
<li>uma fotografia</li>
<li>um arquivo</li>
<li>uma requisição para o webservice</li>
<li>um download do diário oficial</li>
<li>um banner do Governo</li>
<li>a barra padrão do Estado</li>
<li>ou um arquivo na nossa lib</li>
</ul>
</li>
</ul>
<p><del datetime="2009-11-15T10:54:02+00:00">Como resultado da experiência, nossos sites continuam morrendo, porém, aguentando 700 conexões simultaneas e esse valor só é alcançado quando tem muita pesquisa no banco de dados (Dias que sai algo sobre algum concurso público ou muita demissão no Diário Oficial) logo, fica claro, que o problema não é mais do webserver e sim do nosso servidor de Banco. Bom, o nosso webserver atualmente mal chega a 5% de uso, mesmo com as 700 conexões. Só espero conseguir uma maquina nova e mais eficiente para os nossos Bancos de Dados logo!.</del></p>
<p>Update:<br />
Fomos atendidos, estamos com um Xeon Quad Core com 4Gb de memória para o Banco de dados, e, associado com uma otimização do cache do webservice alcançamos mais de 1000 conexões simultâneas sem nenhuma degradação na performance. Detalhe que o webserver ainda é um P4 3ghz com 1gb de memória em que a utilização de processamento não passa de 5%.</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/nginx-webserver-proxy-reverso-e-perfeito/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Autenticação de Usuários no Vórtice PHP</title>
		<link>http://ferrari.eti.br/autenticacao-de-usuarios-no-vortice-php/</link>
		<comments>http://ferrari.eti.br/autenticacao-de-usuarios-no-vortice-php/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 19:02:57 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[vortice]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=71</guid>
		<description><![CDATA[Nesse post vou explicar como adicionar autenticação de usuários no @vorticephp, como base para o sistema vamos utilizar o exemplo que já vem com o framework.
Script de BD:

CREATE TABLE IF NOT EXISTS orgaos &#40;
id int&#40;11&#41; NOT NULL AUTO_INCREMENT,
sigla varchar&#40;50&#41; collate utf8_unicode_ci NOT NULL,
nome varchar&#40;150&#41; collate utf8_unicode_ci NOT NULL,
PRIMARY KEY  &#40;id&#41;
&#41; ENGINE=MyISAM  DEFAULT CHARSET=utf8
&#160;
CREATE TABLE IF [...]]]></description>
			<content:encoded><![CDATA[<p>Nesse post vou explicar como adicionar autenticação de usuários no <a href="http://twitter.com/vorticephp">@vorticephp</a>, como base para o sistema vamos utilizar o exemplo que já vem com o framework.</p>
<p>Script de BD:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> orgaos <span style="color: #66cc66;">&#40;</span>
id int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
sigla varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> collate utf8_unicode_ci <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
nome varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">150</span><span style="color: #66cc66;">&#41;</span> collate utf8_unicode_ci <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM  <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> usuarios <span style="color: #66cc66;">&#40;</span>
id int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
nome varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
email varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
senha char<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> usuarios <span style="color: #66cc66;">&#40;</span>nome<span style="color: #66cc66;">,</span> email<span style="color: #66cc66;">,</span> senha<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Administrador'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'adm@ferrari.eti.br'</span><span style="color: #66cc66;">,</span> md5<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'123'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>eu criei essa tabela com esse usuario e senha no database que já vem configurado no framework para vocês testarem localmente. Você pode configurar a conexão com o seu próprio banco de dados no arquivo app/app.php</p>
<p>Para iniciar vamos criar o objeto do usuário em: app/model/Usuario.php e codificar:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> Usuario<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nome</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$senha</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nome</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$nome</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">senha</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$senha</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>agora que temos o objeto, vamos criar um DAO para realizar operações, crie o arquivo app/model/UsuarioDAO.php e segue o código:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> UsuarioDAO<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getByEmail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM usuarios WHERE email='<span style="color: #006699; font-weight: bold;">$email</span>'&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> Database<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">queryOne</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>vamos para o controller de usuários, crie o arquivo app/controller/UsuarioController.php e segue o codigo inicial:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> UsuarioController <span style="color: #000000; font-weight: bold;">extends</span> Controller<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> login<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Dai a gente cria o nosso formulário de login, edite app/view/usuario/login.php:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;h2&gt;Login&lt;/h2&gt;
&lt;fieldset&gt;
	&lt;form method=&quot;post&quot;&gt;
		&lt;p&gt;&lt;label&gt;E-mail:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;email&quot; /&gt;&lt;/p&gt;
		&lt;p&gt;&lt;label&gt;Senha:&lt;/label&gt;&lt;input type=&quot;password&quot; name=&quot;senha&quot; /&gt;&lt;/p&gt;
		&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Logar!&quot; /&gt;&lt;/p&gt;
	&lt;/form&gt;
&lt;/fieldset&gt;</pre></div></div>

<p>Agora com o form criado, vamos editar a action login do controller Usuario, volte e edite o arquivo app/controller/UsuarioController.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> UsuarioController <span style="color: #000000; font-weight: bold;">extends</span> Controller<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> login<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// se um formulario foi postado</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>post<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// pega as variáveis do post</span>
			<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$senha</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'senha'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// seleciona o usuario, armazena na variavel $u</span>
			<span style="color: #666666; font-style: italic;">// e ainda verifica se o usuario existe</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$u</span> <span style="color: #339933;">=</span> UsuarioDAO<span style="color: #339933;">::</span><span style="color: #004000;">getByEmail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// verifica se a senha digitada combina com</span>
				<span style="color: #666666; font-style: italic;">// a que está no BD</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$u</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">senha</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$senha</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">// remove a senha do objeto</span>
					<span style="color: #000088;">$u</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">senha</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
					<span style="color: #666666; font-style: italic;">// grava a session</span>
					Session<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;u&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$u</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #666666; font-style: italic;">// Cria mensagem de sucesso e redireciona para o index</span>
					Post<span style="color: #339933;">::</span><span style="color: #004000;">setSucesso</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Olá <span style="color: #006699; font-weight: bold;">{$u-&gt;nome}</span>, você está logado&quot;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #990000;">Link</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span>
					<span style="color: #666666; font-style: italic;">// Retorna erro</span>
					Post<span style="color: #339933;">::</span><span style="color: #004000;">setErros</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Senha incorreta!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span>
				<span style="color: #666666; font-style: italic;">// Retorna erro</span>
				Post<span style="color: #339933;">::</span><span style="color: #004000;">setErros</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;e-mail não encontrado!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Para ficar bonita a url vamos criar um route para esta action, edite o arquivo app/routes.php e adicione:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Route<span style="color: #339933;">::</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^login$&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;usuario:login&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Agora o formulário de login já está funcionando, vamos fazer o sistema obrigar o usuario estar logado para fazer qualquer coisa no sistema, para isso edite o arquivo app/controller/MasterController.php, como queremos que para todo o sistema sejá necessário o login, vamos adicionar um construtor nessa classe com o seguinte código:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// se a session &quot;u&quot; não existir, criar uma com um usuario vazio</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Session<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;u&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> Session<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;u&quot;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">new</span> Usuario<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Se a session u tiver um objeto vazio..</span>
	<span style="color: #666666; font-style: italic;">// e o controller/action forem diferentes dos de login</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>Session<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;u&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> controller <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'usuario'</span> <span style="color: #339933;">&amp;&amp;</span> action <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// redireciona para a tela de login</span>
		redirect<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #990000;">Link</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;login&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Bom, com isso já deve estar tudo funcionando de forma eficiente e simples. Qualquer dúvida ou sugestão mande sem hexitar.</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/autenticacao-de-usuarios-no-vortice-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Vórtice PHP Framework &#8211; Introdução</title>
		<link>http://ferrari.eti.br/vortice-php-framework-introducao/</link>
		<comments>http://ferrari.eti.br/vortice-php-framework-introducao/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 10:55:38 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[vortice]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=63</guid>
		<description><![CDATA[Assim como frameworks mais conhecidos, o Vórtice tem uma estrutura de pastas que visa organizar todo o sistema e facilitar na hora da reutilização de código. segue abaixo a estrutura:
1 - app
1.1 - classes
1.2 - controller
1.2 - model
1.3 - view
1.4 - error_docs
1.5 - i18n
1.6 - plugins
2 - core
3 - css
4 - js
5 - templates
5.1 - [...]]]></description>
			<content:encoded><![CDATA[<p>Assim como frameworks mais conhecidos, o <a href="http://vortice.googlecode.com">Vórtice</a> tem uma estrutura de pastas que visa organizar todo o sistema e facilitar na hora da reutilização de código. segue abaixo a estrutura:</p>
<pre>1 - app
1.1 - classes
1.2 - controller
1.2 - model
1.3 - view
1.4 - error_docs
1.5 - i18n
1.6 - plugins
2 - core
3 - css
4 - js
5 - templates
5.1 - nome_do_seu_template
5.1.1 - css
5.1.2 - js</pre>
<h3>1 &#8211; App</h3>
<p>Apesar do framework não exigir nenhuma configuração em ambientes Linux/Unix ele possui um arquivo config.php que é necessário ser usado em caso de instalação em um ambiente Windows para definir a pasta fisica e a pasta virtual do sistema. ainda na pasta app existem os arquivos app.php e funcoes.php, que podem ser utilizados para inicializar instâncias de bancos de dados, criar funções e fazer qualquer coisa que você venha a precisar globalmente no seu site. Aqui também existe o arquivo route.php onde você poderá criar rotas baseadas em expressões regulares, tem um exemplo comentado de como funciona no sistema de exemplo.</p>
<h3>1.1 &#8211; classes</h3>
<p>Essa é a pasta de helpers, coloque ai suas classes de Segurança, as que modificam o fluxo do framework e qualquer classe que você venha a precisar no seu sistema</p>
<h3>1.2 &#8211; controller</h3>
<p>Pasta onde ficam os controllers, o nome do arquivo deve ser: CarroController.php, contendo dentro uma classe CarroController extendondo a classe Controller do framework. cada metodo dessa classe será uma action.</p>
<h3>1.2 &#8211; model</h3>
<p>Modelos do sistema, cada model é constituido por dois arquivos: Carro.php e CarroDAO.php contendo cada um a respectiva classe dentro. A classe Carro guarda a classe de um unico objeto carro (pode extender a classe de framework DTO) e a classe CarroDAO (quepode extender a classe de framework DAO) contêm as operações relacionadas ao objeto Carro (insert, delete, list, etc)</p>
<h3>1.3 &#8211; view</h3>
<p>Views do sistemas, uma view é um arquivo .php que será colocado dentro do template após a execução (substituindo o comentario &lt;!&#8211;conteudo&#8211;&gt; dentro do framework). Cada view deve ser colocada em uma subpasta com o nome do controller que ela pertence: app/view/carro/listar.php e será carregada automaticamente após a action listar do controller carro.</p>
<h3>1.4 &#8211; error_docs</h3>
<p>Páginas de erro, no framework já vem dois modelos.</p>
<h3>1.5 &#8211; i18n</h3>
<p>Pasta onde ficam traduções do sistema (en.conf, pt.conf, jp.conf, etc). Futuramente eu escrevo um post só sobre isso.</p>
<h3>1.6 &#8211; plugins</h3>
<p>Nessa pasta ficam plugins, que são executados exclusivamente antes da página ser enviada ao navegador. Futuramente eu escrevo sobre ela também.</p>
<h3>2 &#8211; core</h3>
<p>Aqui fica o nucleo do framework, caso você tenha vários sistemas usando ele, é possível criar um link simbólico e usar apenas uma pasta para todos os sites.</p>
<h3>3 &#8211; css</h3>
<p>Arquivos CSS globais, que serão carregados para todos os templates</p>
<h3>4 &#8211; js</h3>
<p>Arquivos JS globais, assim como a pasta css</p>
<h3>5 &#8211; templates</h3>
<p>Templates do site, cada subpasta será um template e dentro será necessário um arquivo template.php com o html básico da página.</p>
<h3>5.1.1 &#8211; css</h3>
<p>Aqui ficam os arquivos CSS exclusivos desse template</p>
<h3>5.1.2 &#8211; js</h3>
<p>Arquivos JS exclusivos do template</p>
<p>Fica ai toda a estrutura, qualquer dúvida deixe um comentário.</p>
<p>Faça já o download e experimente: <a href="http://vortice.googlecode.com">Projeto Vórtice PHP</a><br />
Siga o vórtice no twitter: <a href="http://twitter.com/vorticephp">@vorticephp</a> e acompanhe mais novidades seguindo <a href="http://twitter.com/caferrari">@caferrari</a> e <a href="http://twitter.com/luanlmd">@luanlmd</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/vortice-php-framework-introducao/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Vórtice PHP Framework &#8211; Apresentação</title>
		<link>http://ferrari.eti.br/vortice-php-framework-apresentacao/</link>
		<comments>http://ferrari.eti.br/vortice-php-framework-apresentacao/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 10:42:47 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[vortice]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=51</guid>
		<description><![CDATA[Desde junho de 2008 eu e meus colegas do trabalho estamos desenvolvendo uma solução para usar nos sites do Governo do Tocantins e nos sistemas, como a gente tem problemas com a estrutura disponível (hardware!) decidimos criar um framework, que, além de agilizar nossa produção fosse extremamente rápido, consumisse o minimo de recursos possível e [...]]]></description>
			<content:encoded><![CDATA[<p>Desde junho de 2008 eu e meus colegas do trabalho estamos desenvolvendo uma solução para usar nos sites do Governo do Tocantins e nos sistemas, como a gente tem problemas com a estrutura disponível (hardware!) decidimos criar um framework, que, além de agilizar nossa produção fosse extremamente rápido, consumisse o minimo de recursos possível e permitisse o reaproveitamento de código.</p>
<p>Com menos de 2 meses de desenvolvimento, nascia o <a href="http://github.com/caferrari/vorticephp">Vórtice</a> junto com um <a href="http://faleconosco.to.gov.br">projeto inicial</a> que nos direcionou inicialmente no desenvolvimento.</p>
<p>Dentre as diversas características do framework, as mais importantes são:</p>
<ul>
<li> Velocidade;</li>
<li> Padrão MVC com Front Controller;</li>
<li>Rewrite de URL&#8217;s com suporte a regex;</li>
<li> Internacionalização com url&#8217;s únicas por idioma (queriamos que o google indexasse todas as línguas, ex: <a href="http://jalapao.to.gov.br">Jalapão</a>);</li>
<li>Ferramentas para mensagens de erro eficientes, tanto com ajax quanto sem;</li>
<li>O mínimo de configuração possível (no linux não exige nenhuma configuração!);</li>
<li>Fosse possível se conectar em multiplos bancos de dados;</li>
<li>PDO!</li>
<li>Pronto para funcionar com Ajax;</li>
<li>Nos desse algo para trabalhar com versões mobile dos sites;</li>
<li>Renderização em HTML, Json, XML, phpserialize, etc..</li>
</ul>
<p>Veja as demais características no <a href="http://github.com/caferrari/vorticephp">site do projeto</a>.</p>
<p>O projeto quase não foi divulgado devido a falta de Documentação, porém, hoje, como ele está extremamente estável decidi criar este post para apresentá-lo. caso você queira testar, é só <a href="http://github.com/caferrari/vorticephp">baixar</a> e brincar. Ele já vem com um projeto de exemplo que ajuda a ter uma noção legal das funcionalidades.</p>
<p>Para finalizar alguns projetos usando ele:</p>
<ul>
<li><a href="http://to.gov.br">http://to.gov.br</a></li>
<li><a href="http://jalapao.to.gov.br">http://jalapao.to.gov.br</a></li>
<li><a href="http://secom.to.gov.br">http://secom.to.gov.br</a></li>
</ul>
<p>Aguardo comentários.</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/vortice-php-framework-apresentacao/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
