Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-21 Thread Simon Schick
Hi, Rene

I took a quick look over your code ...

I kind-of like the idea having all logging at one place, but the code is a
bit too messy if you ask me :)
If you would have put it on github and I would fork it - the first thing
I'd do is trying to get rid of the hm-lib and rewriting all in a bit more
object-oriented style, but that's just personal taste ;)
Specially the function rajmvServiceLog_graphs_raphael_calculateData() with
a code of ca. 280 lines is quite long ...
Additionally I think that setting an error-handler who's just returning
false is not a good way. Why not disable error-handling or write code that
produces no errors?

I think it would be good to mention that you're using the library adodb (
http://adodb.sourceforge.net/) and sitewide_rv (is it that?
http://mediabeez.ws/) or am I guessing wrong?

You're talking about a sql-file ... has my anti-virus-program removed
something here?

Please don't see that as destructive critic, but as hints what I would do
if I get to do with this code.

Bye
Simon

On Mon, May 21, 2012 at 12:46 PM, rene7705  wrote:

> Hi.
>
> I wasn't happy with the fact that Google Analytics doesn't record many
> of the hits on my sites, so I decided to roll my own analytics
> software, and opensource it.
> It's now in a state where I can request early comments.
> You can view a demo at http://mediabeez.ws/stats (under construction,
> may fail at times) (browser compatibility may be an issue, I built it
> with chrome, should work in firefox too, but won't (ever) in IE.)
> If you click on the graph while the details for a given day are
> visible, you will see the errors for that day in a DIV below the
> graph.
>
> Normally you'd hide the error details and $hits for anyone's who's not
> registred as a developer, of course. I've turned it on for all at the
> moment, so you can comment on that feature and review my results array
> $hits.
>
> I've opted, for simplicity of design, to store all settings I thought
> could be remotely interesting in a mysql db (see attached sql init
> file) (which is filled from PHP every time a page is delivered, and
> again from JS when the page has initialized fully, or does a HTML5
> History API location.href change), and then use PHP to retrieve all
> rows for a given datetime-range, and do the totals calculations in a
> php loop.
> I'm only keeping 1 row from the db in memory at any given time, but
> I'm building up a large deep array with the totals information in the
> php loop that goes over the rows.
> I'm wondering if this is a good approach, though. Maybe I should let
> the totals be calculated by the mysql server instead.
>
> I was thinking to let the totals calculations stay in php, and be
> executed from a cron job every hour. Only for the current month would
> you need to re-calculate every hour.
> I haven't figured out yet how to for instance only re-calculate the
> last hour, store results per hour, and then calculate the day and
> month totals from that "hourly cache" data when needed.
> I don't have a clue about how big companies do their totals
> calculations (for sites that get way more hits than mine, which is
> something i'd like to be able to support with my own analytics code),
> and would like to know how big companies do this.
>
> I've included the relevant draft code as attachment files to this
> mail, for your review. Please let me know if I have forgotten to
> include relevant code..
>
> As always, thanks for your time,
>  Rene
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-21 Thread rene7705
On Mon, May 21, 2012 at 1:17 PM, Simon Schick
 wrote:
> Hi, Rene
>
> I took a quick look over your code ...
>
> I kind-of like the idea having all logging at one place, but the code is a
> bit too messy if you ask me :)
> If you would have put it on github and I would fork it - the first thing I'd
> do is trying to get rid of the hm-lib and rewriting all in a bit more
> object-oriented style, but that's just personal taste ;)
> Specially the function rajmvServiceLog_graphs_raphael_calculateData() with a
> code of ca. 280 lines is quite long ...

280 lines is long?! :)

> Additionally I think that setting an error-handler who's just returning
> false is not a good way. Why not disable error-handling or write code that
> produces no errors?

returning false in an error handler means "do the default error handler plz"..

>
> I think it would be good to mention that you're using the library adodb
> (http://adodb.sourceforge.net/) and sitewide_rv (is it
> that? http://mediabeez.ws/) or am I guessing wrong?
>
> You're talking about a sql-file ... has my anti-virus-program removed
> something here?

Could have, I did include it as an attachment in my OP.

>
> Please don't see that as destructive critic, but as hints what I would do if
> I get to do with this code.

I don't think your words are destructive criticism ;)

>
> Bye
> Simon

Yes, this rajmvServiceLog is tied into other components of mine that
I've opensourced at http://mediabeez.ws
And I agree it's not perfect yet by any standard..

hm.php is used for it's memory-efficient json encoding routines, to
write out the results without building up a large text string with
json_encode().

I'm not inclined to make the PHP code object oriented at this time,
but once released I would allow anyone to OOP it.
I will OOP the javascripts though.

I also don't think I'm going to host my opensourced code (including
this analytics code) on github, I put out a .zip on
http://mediabeez.ws instead, but you can still fork as far as I'm
concerned. I often develop new code that updates older components in
the package, and maintaining forks on github seems like a bit of a
headache to me.. But I'll gladly incorporate improvements made by
others back into my own code base, with credits of course.





>
> On Mon, May 21, 2012 at 12:46 PM, rene7705  wrote:
>>
>> Hi.
>>
>> I wasn't happy with the fact that Google Analytics doesn't record many
>> of the hits on my sites, so I decided to roll my own analytics
>> software, and opensource it.
>> It's now in a state where I can request early comments.
>> You can view a demo at http://mediabeez.ws/stats (under construction,
>> may fail at times) (browser compatibility may be an issue, I built it
>> with chrome, should work in firefox too, but won't (ever) in IE.)
>> If you click on the graph while the details for a given day are
>> visible, you will see the errors for that day in a DIV below the
>> graph.
>>
>> Normally you'd hide the error details and $hits for anyone's who's not
>> registred as a developer, of course. I've turned it on for all at the
>> moment, so you can comment on that feature and review my results array
>> $hits.
>>
>> I've opted, for simplicity of design, to store all settings I thought
>> could be remotely interesting in a mysql db (see attached sql init
>> file) (which is filled from PHP every time a page is delivered, and
>> again from JS when the page has initialized fully, or does a HTML5
>> History API location.href change), and then use PHP to retrieve all
>> rows for a given datetime-range, and do the totals calculations in a
>> php loop.
>> I'm only keeping 1 row from the db in memory at any given time, but
>> I'm building up a large deep array with the totals information in the
>> php loop that goes over the rows.
>> I'm wondering if this is a good approach, though. Maybe I should let
>> the totals be calculated by the mysql server instead.
>>
>> I was thinking to let the totals calculations stay in php, and be
>> executed from a cron job every hour. Only for the current month would
>> you need to re-calculate every hour.
>> I haven't figured out yet how to for instance only re-calculate the
>> last hour, store results per hour, and then calculate the day and
>> month totals from that "hourly cache" data when needed.
>> I don't have a clue about how big companies do their totals
>> calculations (for sites that get way more hits than mine, which is
>> something i'd like to be able to support with my own analytics code),
>> and would like to know how big companies do this.
>>
>> I've included the relevant draft code as attachment files to this
>> mail, for your review. Please let me know if I have forgotten to
>> include relevant code..
>>
>> As always, thanks for your time,
>>  Rene
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-21 Thread Matijn Woudt
On Mon, May 21, 2012 at 2:31 PM, rene7705  wrote:
> On Mon, May 21, 2012 at 1:17 PM, Simon Schick
>  wrote:
>> Hi, Rene
>>
>> I took a quick look over your code ...
>>
>> I kind-of like the idea having all logging at one place, but the code is a
>> bit too messy if you ask me :)
>> If you would have put it on github and I would fork it - the first thing I'd
>> do is trying to get rid of the hm-lib and rewriting all in a bit more
>> object-oriented style, but that's just personal taste ;)
>> Specially the function rajmvServiceLog_graphs_raphael_calculateData() with a
>> code of ca. 280 lines is quite long ...
>
> 280 lines is long?! :)

I haven't had a good look at your code yet, but let me comment on this
one anyway.
280 lines is long. Take any big project, Linux kernel
(http://lxr.linux.no/linux), Wine (http://source.winehq.org), or an
large PHP project, for example Drupal, and you'll probably only find a
few functions that long.

>
>> Additionally I think that setting an error-handler who's just returning
>> false is not a good way. Why not disable error-handling or write code that
>> produces no errors?
>
> returning false in an error handler means "do the default error handler plz"..

Why are you setting the error handler then? Are you trying to override
an error handler set by other scripts?

>
>>
>> I think it would be good to mention that you're using the library adodb
>> (http://adodb.sourceforge.net/) and sitewide_rv (is it
>> that? http://mediabeez.ws/) or am I guessing wrong?
>>
>> You're talking about a sql-file ... has my anti-virus-program removed
>> something here?
>
> Could have, I did include it as an attachment in my OP.

The mailing list probably removed it. You should never send
attachments to a mailing list, instead host them somewhere on the web
and link to it.

>
>>
>> Please don't see that as destructive critic, but as hints what I would do if
>> I get to do with this code.
>
> I don't think your words are destructive criticism ;)
>
>>
>> Bye
>> Simon
>
> Yes, this rajmvServiceLog is tied into other components of mine that
> I've opensourced at http://mediabeez.ws
> And I agree it's not perfect yet by any standard..
>
> hm.php is used for it's memory-efficient json encoding routines, to
> write out the results without building up a large text string with
> json_encode().
>
> I'm not inclined to make the PHP code object oriented at this time,
> but once released I would allow anyone to OOP it.
> I will OOP the javascripts though.

Note that OOP is not always the best way to go. Haven't taken a close
look at the source so can't comment.

>
> I also don't think I'm going to host my opensourced code (including
> this analytics code) on github, I put out a .zip on
> http://mediabeez.ws instead, but you can still fork as far as I'm
> concerned. I often develop new code that updates older components in
> the package, and maintaining forks on github seems like a bit of a
> headache to me.. But I'll gladly incorporate improvements made by
> others back into my own code base, with credits of course.
>

Putting it on github makes it easier for people to have a look at your
code before deciding on using it or not. If you're only putting it
there, you don't have to worry about forks because they don't have
anything to do with your repo, that's up to the people who fork it.
Putting it on github will increase the popularity, and will probably
also make developers want to 'upgrade'  your code. It's up to you.

A few other comments:
- Maybe you should think about another name? rajmv.. is not easy to remember.
- You're formatting is confusing, for example function names. They
start with lowerCamelCase, and then you go on underscore_formatting..
- in json_encode_*, there's probably a better way to write
if (
$c == ' ' ||
$c == '"' ||
$c == "'" ||

you could use in_array with a predefined array for example.
- Why do you have atleast 4 large encode functions? If you really need
4 different, then you might want to think about moving shared code to
sub functions and call them instead of duplicating so much code
(especially the large if statements look ugly being duplicated 4
times)
- If you want people to comment on code, please be so kind to remove
any unused commented code.

Hope this helps,

Matijn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-21 Thread rene7705
I see that the sql file didn't come through to the web archive of this
list, so I'm posting it in-message here once more, for those
interested;

drop table if exists rajmvServiceLog;
create table rajmvServiceLog (
id integer not null AUTO_INCREMENT,
initial_id varchar(250),
php_remote_addr varchar(20),
php_time integer,
php_referrer longtext,
php_request_method varchar(10),
php_script_filename longtext,
php_script_name longtext,
php_self longtext,
php_request_uri longtext,
php_query_string longtext,
php_get_vars longtext,
php_post_vars longtext,
php_cookie_vars longtext,
php_http_host longtext,
php_http_connection varchar(250),
php_http_user_agent longtext,
php_http_accept varchar(250),
php_http_accept_encoding varchar(250),
php_http_accept_language varchar(250),
php_http_cache_control varchar(250),
php_http_accept_charset varchar(250),
php_server_name varchar(250),
php_server_addr varchar(20),
php_server_port varchar(10),
php_server_software varchar(250),

php_context_json longtext,
php_error_json longtext,

js_location_href longtext,
js_location_hash longtext,
js_time integer,
js_milliseconds_since_init_of_page integer,
js_date_time_txt varchar(250),
js_referrer longtext,
js_screen_width integer,
js_screen_height integer,
js_browser_width integer,
js_browser_height integer,
js_error_message longtext,
js_error_url longtext,
js_error_line integer,
primary key (id)
);

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] [missing] images .htaccess

2012-05-21 Thread muad shibani
Hi there

how I can ignore [missing]  images and other files completely in .htaccess
 from being processed by the index.php file



RewriteRule .* index.php [L]

the CMS itself gives 404 error page for unknown request

thanks in advance


Re: [PHP] [missing] images .htaccess

2012-05-21 Thread Simon Schick
Hi, Muad

I guess that you have a cms (would be nice to name it if it's not a
custom one) that handles all requests coming into the system. Think
now of How you know if the requested uri is a missing-image and write
it down as mod_rewrite rule.
Is this the only line you have in your .htaccess-script? What does the
cms with the request if the file is available? Does the cms here just
works like a proxy or is it doing some other magic? May it checks some
permissions first before it ships the file?

If you want to ungo passing requests for images to the cms, I'd do it like this:
It checkes if the request is pointing to a directory where only images
(or downloadable files) are located and lets apache do the rest to
provide the file. Or check for file-endings ...

RewriteRule \.(gif|jpg|jpeg|png)$ - [L]

You can then guess that all files ending with .jpeg, .jpg, .gif, .png
or similar are pictures, bypass the cms and let apache ship the file
or apaches 404-page if not available.
But this has nothing to do with PHP itself but is an apache-configuration.
Here's a beginner guide where I copied the line above:
http://www.workingwith.me.uk/articles/scripting/mod_rewrite

Bye
Simon

On Mon, May 21, 2012 at 5:55 PM, muad shibani  wrote:
>
> Hi there
>
> how I can ignore [missing]  images and other files completely in .htaccess
>  from being processed by the index.php file
>
>
>
> RewriteRule .* index.php [L]
>
> the CMS itself gives 404 error page for unknown request
>
> thanks in advance

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] requesting comments on rajmvServiceLog (access + error logging through PHP and JS to MySQL)

2012-05-21 Thread tamouse mailing lists
On Mon, May 21, 2012 at 7:31 AM, rene7705  wrote:
> On Mon, May 21, 2012 at 1:17 PM, Simon Schick
>  wrote:
>> Specially the function rajmvServiceLog_graphs_raphael_calculateData() with a
>> code of ca. 280 lines is quite long ...
>
> 280 lines is long?! :)

In general, yes. 280 lines is long. Too long, likely. Usually it
indicates you aren't designing your code in a top-down fashion, and it
is a high candidate for refactoring in order to break out into
reusable functions. A rule of thumb is no more than 50 lines per
function, most much less. Back in the day when we didn't have nifty
gui screens and an 24 line terminals (yay green on black!), if a
function exceeded one printed page, it was deemed too long and marked
for refactoring.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php