Update web directory after a SVN commit: the final solution

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 23-08-2010

0

Hi,

i wrote about this in the past (you can see some post at the end) but i’m writing again as i found the perfect solution to make a SVN update after a commit to a web directory.

the difference between the old and this new one, is that the old make a svn update in all the working copy, something like that is not a problem if you have some files, but when you have like 100K files, it takes too much time and resources. so the idea was to get a list of changed directories after each commit and run a svn update on each directory.

for this i used some bash scripting and a C program (the C program is needed when the files do not belong to the user who execute the post-commit script).

in the post-commit script put something like this:

svnlook dirs-changed /path/to/your/repository > /tmp/dirschanged

while read line
do
/path/to/C/Binary/updateFolder $line
done < “/tmp/dirschanged”

and save it. remember that after the svnlook (that is what return the list of directories that has been modified)  and before the while, you can use sed to change any path of your repository and convert it into a valid full path in your web directory.

then, create a .c file and paste this code to make the binary:

#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{

int i;
for (i = 1; i < argc; i++)  /* Skip argv[0] (program name). */
{

printf(“making update to  %s \n”,argv[i]);
execl(“/usr/bin/svn”, “svn”, “update”,argv[i],
(const char *) NULL);
}
exit(0);

}

compile and set a chmod +s, and is done :D . the binary will accept any amount of arguments as paths to run the svn update, anyway i’ll recomend to make 1 at time, so you have more control of it.

i know that this code could be improved, maybe using less bash scripting and more C coding, but i’m not good as before in C, so for me was more easy to make the loop and event the replacements with sed in the bash scripts.

i hope this help you in some way

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Apache or ngnix ?

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 13-07-2010

0

Hi,

some weeks ago someone told me that ngnix was better than apache as can handle more users and was more stable with big traffic. as i usually don’t discard the opinions and recommendations i receive, i started researching about this as i didn’t know anything about ngnix. for that, i wanted to write this post so can save you some time looking at the internet :D . for my research i used sources as serverFault.com and other blog post where it benchmark different php scripts (custom and wordpress blogs).

Apache and ngnix, what is the diference?

the main difference between ngnix and apache is that the way both web servers handle the user requests. apache have a multi thread architecture and ngnix have a unique thread architecture to process the user request. this is the main difference between both, the other important difference are the config files and the rewrite rules, where the format is difference from apache and a new user need to learn this new way to format the htaccess and the config files. other than this, both can manage virtual hosts, aliases,  etc..

Define the goal or purpose to choose.

i always say that there is no a complete tool or a ultimate language and technologies, each decision of what tool to use depends of the requirements of the project. in this case is the same, you need to evaluate your project to decide what to use.

after my research  i found that ngnix have a greater performance, in terms of memory needed, when the ngnix is serving static content. static content is called all what are images, videos, flash, files etc.. and optimized and cached dynamic pages, like a wordpress blog with super cache plugin.

in term of speed both are almost equal, having a difference in favor to ngnix at serving static files.

Conclusion

when i started to research this, i have in mind 2 projects, one of them was a non-optimized sites and the other a highly optimized site that doesn’t have a lot of cached pages but have a lot of static content.

then my conclusion was that you need to choose depending of your project requirement, to use apache or ngnix or both (yes, both can be used at the same time).

if you have a crappy php site, don’t bother you,   ngnix don’t going to give you any improvement, better, invest your time to improve the code.

if you have a highly optimized site and cached most of their pages and you don’t bother to rewrite any htaccess or config file in this new format, ngnix will give you a improvement in your server.

if you have a mixed site, highly optimized, but not too cached her pages, you can have both running, ngnix serving static content and apache serving the dynamic content, this will improve in some way your site with a better load balancing proportional of the percentage of static files are serving.

i hope this help you to decide in this matter, i’ll post later a tutorial of how to install ngnix and apache togheter :)

Regards,

Shadow

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

GlotPress: collaborative translation

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 05-06-2010

0

Hi,

for a tweet of one of the person i follow, i noticed the existence of this project.

basically GlotPress provide a web end and administration for translation of phrases for development projects.

is a nice platform, easy to use and the well implemented usability make the translations something fun and not something boring as always :P . i have contributed with some translations from english to spanish for the gravatar project.

the project is still under development, you can see more info here.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Update web directory after commit in SVN

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 05-03-2010

0

Hi,

some new tips about subversion :D

if you need to update a web directory after someone make a commit just follow this guide: http://subversion.apache.org/faq.html#website-auto-update

i wanted to post this why it take me some time to figure out that a simple bash script don’t going to work and even if it worked with some tricks, i always getting a merge and not an update of the repository :P

some thing that the faq don’t mention is how to compile the program, if you are a newbie and don’t know how to do it, just run this command

gcc your_file_name.c -o your_binary_name

i hope it helps :D

Regards.

Shadow.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Foreach objects in smarty

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 05-03-2010

0

Hi,

recently i changed how a REST API sent the info from xml to JSON, that mean that now the arrays was converted into objects after the json_decode(). don’t was too much problem till i see that my smarty templates don’t worked anymore :(

the change of each file don’t was an option and the convert from objects to arrays is wasting resources in nothing, so i made a hack in the smarty main class :D

basically in the file Smarty_Compiler.php at line numero 1203 i added this if():

if(is_object($from)){
$output .= “\$_from = $from;”;
$output .= “foreach(\$_from as $key_part=>$item){“;
}else{

and in the else, you wrap all the other code to parse arrays :D

now the foreach will parse objects and arrays :D

i hope it helps.

Regards,

Shadow.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Weird php bug? : “” == 0

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 18-01-2010

0

Hi,

just happened something weird, i have a sentence like this:

if($var!=”"){

}

the thing is that the var sometimes get the value of 0, and for some reason it returned false (something that never happened to me before in 3 years programming in php). anyway i understand that can be considered as normal, but i wondering if is a bug :s (why it don’t happened before )

the solution?

if($var!==”"){

}

i hope has been useful :D

Regards,

Shadow.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

serialize array with javascript (php compatible, associative arrays and mootools)

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 04-10-2009

1

Hi,

one of the task i was need to do, was to write a javascript funtion to serialize a array, so can be sent through ajax.

the task wasn’t easy, why searching on the web i only found partially working functions (some that only proccess numerical arrays, other even’t didn’t worked, and wasn’t recursive) but serching i come up with the perfect javascript serialize function ever :D

in resume it can:

  • parse numerical arrays
  • associative arrays
  • mixed arrays
  • multidimensional arrays
  • it detect if the index or values of the element it’s int or string and parse it accordingly
  • mootools compatible (read below what i mean with  this

so i dont want you wait anymore, here it’s the function:

function serializeArray(ArrayElem)
{
var cont=”";
var counts=0;
var jj;
var res = “”;

for(jj in ArrayElem)
{
//if mootools it’s included, this hack prevent that the function parse also the prototype objects
if(jj==”$family”){
res = ‘a:’+counts+’:{‘;
res += cont;
res += ‘}’;
return res;
}
if(isInt(jj)){
cont += ‘i:’+jj+’;';
}else{
cont += ’s:’+jj.length+’:”‘+jj+’”;’;
}
if(isArray(ArrayElem[jj])){
cont += serializeArray(ArrayElem[jj]);
}else{
if(isInt(ArrayElem[jj])){
cont += ‘i:’+ArrayElem[jj]+’;';
}else{
cont += ’s:’+ArrayElem[jj].length+’:”‘+ArrayElem[jj]+’”;’;
}
}
counts++;
}

res = ‘a:’+counts+’:{‘;
res += cont;
res += ‘}’;

return res;
}

function isArray(obj) {

return obj.constructor == Array;

}

function isInt(myNum) {
// get the modulus: if it’s 0, then it’s an integer
var myMod = myNum % 1;

if (myMod == 0) {
return true;
} else {
return false;
}
}

i going to explain some things about this function:

  1. the isInt() function it’s very simple, i dont know if it can fail with some weird value, but at least it’s fast and cross browser compatible
  2. i’m using a counter and not the length propertie of the array why with associative array it return 0
  3. as you see, there it’s a hack for mootools, that it’s it make it “compatible”, whiteout that hack the function also parse all the native properties and elements added at the moment when you add mootools to the document. i didn’t know any other form to stop it, so if you know something advise :D
  4. in the php that receive the serialized array, remember to use stripslashes if the magic quotes are ON and maybe you going to need to use html_entity_decode() (at least that was my case) to convert the doble quotes character to signs.

i hope it help you, it’s very easy to use and understand and can save you some hours of work :D

Regards,

Shadow

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Import big xml to oscommerce or mysql database

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 02-10-2009

0

Hi,

recently i have needed to do a script that parse a big xml file and insert it to a oscommerce database. i wanted to write this post why can be useful if you are doing something like this and maybe with other CMS system or database schema :)

the script no only need to insert the products, also download the images, check if the product already ,xist and update the product with the info of the xml. i don’t going to describe the trivial process of check for the product, make the queries etc.. if you are seeing this post you are run with some of the 2 essential problem:

1)out of memory error

2)session timeout, php execution time limit or 500 internal error

so, here are the soltuion for your problems :)

1) out of memory error

this it’s happen why surely you are usng the xml_parse() to parse the xml. this function always going to give you a out of memory error why need to load all the document in the memory to use it.

the solution it’s simple, use XMLReader this going to allow to load all the xml file and let you review each element of the xml. the documentation it’s very clear of how to use it and with some of testing, in a few hours you should have working your parse function :) . the only “problem” can be it’s that’s only available from php version biggers that 5.1.2, i don’t think so but maybe you can run with some problem in some host :)

2)session timeout, php execution time limit or 500 internal error

well, this error can be fixed but going to be you more effort and ugly code but i didn’t thinked any other posible solution for this :s

if you have a php execution limit error, simply add: set_time_limit(0); this this going to let you run the script forever. of course this isn’t safe, why if you have a bug or something, can be running forever and consumming so much memory than you going to have your shosting account suspended, so be sure to test everything before you run it live :)

after you set the execution time to 0, if you still have a timeout error or a 500 internal error it’s surely happening by the mysql queries. the xml parse it’s very fast with XMLReader but the real time take the mysql queries and if you are using oscommerce and need to check too much thing going to be a nightmare :P

the only solution i come up for this, was to re-execute the script till i procesed all the xml. basically i have parse the xml into a multidimensional array like this:

$rows[$rownumber][elements]

so, i process all the xml (in this time i processed a 3MB xml) to a array, send it to a function that update the DB and processing it in 200 rows parts. after the part finished, i keep the number of rows processed and printed:

echo “processed…. $numberofrows”;

echo ‘<meta http-equiv=”refresh” content=”4;url=xmlimport.php?f=’.$filename2.’&cont=’.$continue.’&start=’.$finished.’” />’;

i used a meta and not a header() why with header it still crashed with a 500 internal error.

so, when the script load again in the function that parse the xml, i set:

if($_GET['cont']==true){

for($i=0;$i<$_GET['start'];$i++){

$xml->read();

}

}

with that, i have moved the pointer of the xmlReader object to the last inserted row, and then start to parse the rest. it continue till the rows to parse are none and the script stop :)

i hope this help someone to resolve this problem :)

Regards,

Shadow.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Learning php: Lesson 1

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 16-07-2008

0

Hi,

i dont know how much lines of code i write in my life, surely i wrote more than 1000 files of php of 300 lines each, at least… for that, i want to share my knowledge about this marvelous languaje, and for that, we need to start form the beginning.:D

i try to post 1 entry per day, i hope in 15 or 20 days, you can learn with my tutorial, all the basics and advanced things about the web develoment with php.

well, now, start with the lesson:

Tips to make a joomla component

Posted by shadow_of__soul | Posted in Uncategorized | Posted on 14-07-2008

0

Hi,

working like a freelance developer you are forced to make several things, using several tools,apis, codes and framework. for a experienced developer, it’s easy to make code for a new platform, if the documentation it’s available and it’s clear.

in the past few days i has been doing a component for joomla, and it’s not hard, but has been some difficult to find some specific information about the framework. for this, i want to use this post explain the principal function and how it work :D

note:

in the bottom you going to find a hello world component like a example of all what i’m talking here.