Archivio per la categoria ‘ajax’

development of large used application on php 5

On my free time I work on an open source application called phpCollab, a php based project managment software. I love that application, and I use it normally for my own work to manage my clients on differents works.

Actually the development is very slowly, the first reason is that all the developer are very busy with their paid jobs and the second one is that the code isn’t very easy to manage (it has a lot of library file and code redundancies).

phpCollab has grown a lot and with a lot of different parents, so now there’s a lot of hard-reading code without a single line of comment :( .

Quite a month ago during an hack for a client, I’ve decided, for the next third release [maybe in the year 2135.... ;) ], to rewrite all the code using php 5 (with a DB layer like creole/propel), a modular/pluggable approach like WP and off course a lot of ajax.

For the latest two item there wasn’t a problem, but some of community members were not very happy about the use of php5. Actually the software has quite 2 thousands (known) installation around the world and a lot of them are on old server with php older than 4.4.x and the users don’t want to have problem with php 5 incompatibilities. Maybe php 5 (and its goodies) isn’t yet well suited for an application like phpCollab? Or a pragmatic php 4 OO rewrite is enought?

Does anyone has some case studies about php 4 to 5 software migration?

ajax encoding pt.2: from js->escape to php->urldecode

Another brick to solve the encoding issue with ajax is settled, last week I ranted about the problem on showing data from a remote script inside a page encoded with ISO-8859-1.

This time I’ve the reverse problem, I’ve to save some data from a form to a db and then show it on another page. As usual xmlHttpRequest send data in UTF-8, so my data results always corrupted.

This time the solution is very simple, first I encode the data with javascript using the escape function then on the remote script I use the php function urldecode.

So a string like ÎÑTËRÑÅTÌÔñ�L will be escaped to %CE%D1T%CBR%D1%C5T%CC%D4%F1%C1L and then urldecoded back to ÎÑTËRÑÅTÌÔñ�L :)

ciuaz

A bad way to use ajax

A friend of mine ask me about using ajax to create a small counter for his site, he wanted to update the counter every xx seconds to show how many users are visiting his site at the same time.

The idea is nice but after a 10 second thinking I’ve stopped him to implement such feature.

Why? Think about to use a small file (1kb) where you save the counter value.
Now, select as refresh time 5 seconds, every minutes a user will receive 12 refresh of the counter element (=12kb).

This isn’t a real problem for a single user but if the site has more than 100 users online? Every minutes the script will use quite 1Mb of server bandwith…

Do you see the path? If you use an ajax counter like this in a community forum with 100 different browser session, and is not rare that a user opens more than one session to read different posts, always online you’ll waste 60Mb/h => 1,4Gb day!!!

A good use of ajax should be very usefull, but a bad use will surely kill your servers…

ciuaz

utf-8 madness

As I wrote, I’m working on a stupid ajax (intranet) site but I’ve a lot of problem with charset encoding.

I’ve to publish, for legacy problem, all the intranet site using old ISO-8859-1 encoding BUT using the js XMLHttpRequest the data I receive is always UTF-8.

Unlucky I cannot use php to re-parse the data and to trasform to a latin encoding, anyone has a good idea to resolve this? Can I force another encoding on XMLHttpRequest?

Ok, I’m too tired to see the obvious… To resolve the problem I had simply forced the encoding via the php header function in the file I call remotely:

header(“Content-Type: application/x-javascript; charset=ISO-8859-1″);
echo $output;

now the browser show the right ÎÑTËRÑÅTÌÔñ�L strings :)

ciuaz