手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2024年11月的文章

按照AdSense要求投放广告代码

虽然我的google adsense广告几乎没有人点,但是今天看到adsense小组说的重复投放的事情,还是有必要转帖一下,帮助其他人,免得重复 。。。

AdSense中文小组告诉我们:

自从我们发布了服务 器端广告设置这个功能以后,大家修改代码就更加方便了。Google AdSense代码投放的最好办法是直接通过帐户获取代码并嵌入到要投放的网站页面源代码中,但是我们发现有一些网站调整了AdSense广告代码的展 示。比如在一部分文学网站和一些内容管理系统中有类似于此的AdSense代码投放方式:

<div id="span_ad_01" style="display:none">
<script type="text/javascript"><!--
google_ad_client = "pub-1234512345123451";
google_ad_slot = "1234567890";
google_ad_width = 300;
google_ad_height = 250;
google_color_border = "E32BF1";
google_color_bg = "689BF1";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<div id=”span_ad_04”></div>
<script>
span_ad_04.innerHTML=span_ad_01.innerHTML;
span_ad_01.innerHTML="";
</script>


该种广告投放方式会导致一个广告位对系统产生多次广告查询,浏览器会多次处理这些请求,这样会影响用户体验。为了避免出现该问题,我们建议您按照以下方式修改广告代码:
1. 直接粘贴您的AdSense代码到页面源代码中
2. 通过iframe调用广告代码,但是一个页面只能嵌入一个iframe单元

AdSense 产品部门正在对广告后台进行一些调整以提升广告投放的准确性,如果您在使用类似上述原理的方式投放Google AdSense广告,那么接下来的这些调整可能会影响到您网站的广告投放。我们建议您尽快按照上述符合要求的方式投放AdSense广告,以避免接下来的 调整影响到您网站的AdSense广告投放。

我们注意到大家采用该方式以解决页面内容下载过慢的问题,但是从我们目前的数据和发布商反馈来看,AdSense广告在本地区的投放是不会影响页面内容下载的。

我们会通过系统邮件通知一部分以该方式投放代码的发布商,也希望大家相互转告,尽快实现代码的更换,以避免接下来的产品调整影响您网站的广告展示。如果您对此还有疑问,也欢迎通过支持链接和我们联系。

Tags: google, adsense

PHP框架:Treacle 介绍

群友Bopo自己开发了一个PHP的framework。Bopo从认识到现在,大概也有四五年的时间了吧,不过这个框架的年龄并不是特别长,大概只有2年多左右。最早这个框架BOPO是自己做项目的时候一点点的做的,但后来他终于有想法将它逐步扩大成为了一个框架。

最初看到框架的时候,还是一个雏型,现在,比以前好多了,所提供的支持也多了很多。让我们来看看这个糖浆究竟有些什么。

Treacle 是个什么呢?

Treacle 为开发者轻松、快捷的创建应用程序提供帮助。Treacle 框架简单、清晰,容易理解和学习,并且有完全中文化的文档和丰富的示例程序降低学习成本。

Treacle 有什么特点?

  • 完全跨平台
  • 完全支持 PHP5
  • 不倚赖特别的 PHP 扩展模块
  • 简单、容易理解的 MVC 模型
  • 丰富的助手对象和组件
  • 开放源代码,完全中文化的注释和文档
  • 商业公司提供技术支持

如何获取技术支持?

您可以通过参与我们的论坛来获得技术支持。
官方网址:http://www.treacle.cn/

可能现在有些简陋,但是期待一下吧。

Tags: framework, treacle, bopo

ThinkPHP发布1.5Lite版

一大早流年就在群里说发布了Lite版本,但是我还没有欣赏一下具体的代码,好象这个版本的想法是用Yhustc那里冒出来的,因为他的Yblog就自行对ThinkPHP 1.5进行了简化只保留了常用的功能,比如:数据库只支持MYSQL(也是,这个博客程序只用MYSQL,其他的一些驱动就可有可无了)。于是流年在这个想法的基础上,花了几天时间进行了Lite的构造。(估计几天的休息时间就这么没有了吧)

官方原文:http://www.thinkphp.cn/Blog/25

发布该版本的原因是很多应用开发要求较高的性能并且不需要很多特殊的功能

Lite版本提供网站开发最需要的功能,优化性能,更适合大型项目!

[ 功能列表 ]

编译缓存
自动生成
异常处理
URL模式
语言包支持
模板主题支持
空模块和空操作
前置和后置操作
智能数据表识别
自动加载
标签库
类库导入
Vendor支持
ADSL方法
跨库操作
字段映射
URL组装
URL伪静态
原生SQL操作
多数据库连接和切换
分布式数据库支持
支持MySql和PDO
惯例配置
项目配置
动态配置
模块配置
静态缓存
动态缓存
模板引擎和扩展支持
日志处理
SQL日志
调试模式
运行时间显示
页面Trace
类库扩展
自动验证
自动完成
CURD基本
AR模式基本
连贯操作

[ 注意事项 ]
去掉了ORG类库包(自己可以增加扩展)
保留文件缓存驱动
保留内置模板引擎和PHP模板引擎驱动
查询条件只支持字符串
CURD接口和数据库接口已经更改(和标准版不兼容)
视图模型和关联操作已经去掉
模型的数据操作保留了 add save delete find query execute 增加了select方法 并做了参数的调整
去掉了自动获取数据表字段信息 改由模型自己定义或者不定义
保留运行信息和页面Trace显示
去掉了URL路由功能(该部分功能可以用空模块和空操作取代)

[ 下载Lite版本 ]

Lite版本适合对TP有一定了解的开发人员,并且有PHP开发经验和足够的扩展能力。

Tags: thinkphp, lite

jQuery 1.3 中文文档发布

jquery 1.3刚刚出来没几天,shawphy的中文API就基本出炉了,有时候真的挺佩服他们,当我们在娱乐的时候,他们还在努力的为我们这些人造福。我没有什么其他能力,只能做到代为传播了。同时也是希望有更多的人参与,可以让我们这些使用者也能够更加方便。

网址:http://shawphy.com/2009/01/release-jquery-doc-cn-1-3.html
原文如下:

jQuery 1.3自从2008年1月14日发布后,后引来了各界的关注。我们也随即投入到翻译文档的工作中来。经过4天的努力,终于完工了。这个版本更新了不少东西

changelog:

2009-01-18 16:06:52 +0800
* triggerHandler 进一步说明
* trigger 进一步说明

2009-01-17 22:37:11 +0800
* live() - 与bind()不同的是,live()一次只能绑定一个事件。
* [attribute!=value] jQuery 1.3中意义改变
* load 的data参数在jQuery 1.3中也可以接受String
+ ajax的error回调的第二个参数可能值”timeout”, “error”, “notmodified” 和 “parsererror”
+ ajax参数xhr
* animate 的duration为0的问题
* show, hide, toggle, slideDown, slideUp, slideToggle 在jQuery 1.3中,padding和margin也会有动画,效果更流畅。
* jQuery(html,[ownerDocument])等效于$(document.createElement(”span”)
* is支持复杂表达式

2009-01-17 18:31:10 +0800
+ jQuery.support.scriptEval
+ 原 Dimension 插件功能(1.2.6版加入jQuery核心)

2009-01-16 19:11:10 +0800
+ jQuery.fx.off
+ toggleClass( class, switch )
+ toggle( switch )
+ toggle(speed,[callback])
* 修改queue和dequeue方法的参数和说明

2009-01-15 22:31:02 +0800
* jQuery(html,[ownerDocument])
+ jQuery.selector
+ jQuery.context
* 效果下的queue和dequeue搬到核心下
+ live()
+ die()
+ closest()
* stop( [clearQueue], [gotoEnd]) 增加两个参数
+ jQuery.support
+ jQuery.isArray( obj )

感谢Cloudream的热情帮忙。还要感谢一揪制作chm版。这个版本还加入了检查更新的功能。如果有需要的同学可轻松查看是否有更新的中文文档(chm版中的检查更新也将同步升级)。

在线查看 下载离线版 bug提交

Tags: javascript, jquery, api

ORDER BY RAND()

本文作者好象是写mysql proxy的,这是他写的关于order by rand的效率方面的文章。事实上我们在使用中是尽量避免采用order by rand这种的,但应该如何写,他给了我们一些其他的解决方法,并将其效率进行了分析,我觉得很有用,就留下来了。

原文网址:http://jan.kneschke.de/2007/2/15/order-by-rand

内容如下:
If you read the MySQL manual you might have seen the ORDER BY RAND() to randomize the the rows and using the LIMIT 1 to just take one of the rows.

SELECT name
FROM random
ORDER BY RAND()
LIMIT 1;

This example works fine and is fast if you only when let's say 1000 rows. As soon as you have 10000 rows the overhead for sorting the rows becomes important. Don't forget: we only sort to throw nearly all the rows away.

I never liked it. And there are better ways to do it. Without a sorting. As long as we have a numeric primary key.

For the first examples we assume the be ID is starting at 1 and we have no holes between 1 and the maximum value of the ID.

move the work into the application

First idea: We can simplify the whole job if we calculate the ID beforehand in the application.

SELECT MAX(id) FROM random;
## generate random id in application
SELECT name FROM random WHERE id = <random-id>

As MAX(id) == COUNT(id) we just generate random number between 1 and MAX(id) and pass it into the database to retrieve the random row.

The first SELECT is a NO-OP and is optimized away. The second is a eq_ref against a constant value and also very fast.

move the job into the database

But is it really necessary to do it in the application ? Can't we do it in the database ?

# generating a random ID
> SELECT RAND() * MAX(id) FROM random;
+------------------+
| RAND() * MAX(id) |
+------------------+
| 689.37582507297 |
+------------------+
# oops, this is a double, we need an int

> SELECT CEIL(RAND() * MAX(id)) FROM random;
+-------------------------+
| CEIL(RAND() * MAX(id)) |
+-------------------------+
| 1000000 |
+-------------------------+
# better. But how is the performance:

> EXPLAIN
SELECT CEIL(RAND() * MAX(id)) FROM random;
+----+-------------+-------+-------+------+-------------+
| id | select_type | table | type | rows | Extra |
+----+-------------+-------+-------+------+-------------+
| 1 | SIMPLE | random | index | 1000000 | Using index |
+----+-------------+-------+-------+------+-------------+
## a index scan ? we lost our optimization for the MAX()

> EXPLAIN
SELECT CEIL(RAND() * (SELECT MAX(id) FROM random));
+----+-------------+-------+------+------+------------------------------+
| id | select_type | table | type | rows | Extra |
+----+-------------+-------+------+------+------------------------------+
| 1 | PRIMARY | NULL | NULL | NULL | No tables used |
| 2 | SUBQUERY | NULL | NULL | NULL | Select tables optimized away |
+----+-------------+-------+------+------+------------------------------+
## a simple Sub-Query is bringing us the performance back.

Ok, now we know how to generate the random ID, but how to get the row ?

> EXPLAIN
SELECT name
FROM random
WHERE id = (SELECT CEIL(RAND() *
(SELECT MAX(id)
FROM random));
+----+-------------+--------+------+---------------+------+---------+------+---------+------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+------+---------------+------+---------+------+---------+------------------------------+
| 1 | PRIMARY | random | ALL | NULL | NULL | NULL | NULL | 1000000 | Using where |
| 3 | SUBQUERY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Select tables optimized away |
+----+-------------+--------+------+---------------+------+---------+------+---------+------------------------------+
> show warnings;
+-------+------+------------------------------------------+
| Level | Code | Message |
+-------+------+------------------------------------------+
| Note | 1249 | Select 2 was reduced during optimization |
+-------+------+------------------------------------------+

NO, NO, NO. Don't go this way. This is the most obvious, but also the most wrong way to do it. The reason: the SELECT in the WHERE clause is executed for every row the outer SELECT is fetching. This leads to 0 to 4091 rows, depending on your luck.

We need a way to make sure that the random-id is only generated once:

SELECT name
FROM random JOIN
(SELECT CEIL(RAND() *
(SELECT MAX(id)
FROM random)) AS id
) AS r2
USING (id);
+----+-------------+------------+--------+------+------------------------------+
| id | select_type | table | type | rows | Extra |
+----+-------------+------------+--------+------+------------------------------+
| 1 | PRIMARY | <derived2> | system | 1 | |
| 1 | PRIMARY | random | const | 1 | |
| 2 | DERIVED | NULL | NULL | NULL | No tables used |
| 3 | SUBQUERY | NULL | NULL | NULL | Select tables optimized away |
+----+-------------+------------+--------+------+------------------------------+

The inner SELECT is generating a constant TEMPORARY table and the JOIN is selecting just on single row. Perfect.

No Sorting, No Application, Most parts of the query optimized away.

adding holes to the numbers

To generalize the last solution we add the possibility of holes, like when you DELETE rows.

SELECT name
FROM random AS r1 JOIN
(SELECT (RAND() *
(SELECT MAX(id)
FROM random)) AS id)
AS r2
WHERE r1.id >= r2.id
ORDER BY r1.id ASC
LIMIT 1;
+----+-------------+------------+--------+------+------------------------------+
| id | select_type | table | type | rows | Extra |
+----+-------------+------------+--------+------+------------------------------+
| 1 | PRIMARY | <derived2> | system | 1 | |
| 1 | PRIMARY | r1 | range | 689 | Using where |
| 2 | DERIVED | NULL | NULL | NULL | No tables used |
| 3 | SUBQUERY | NULL | NULL | NULL | Select tables optimized away |
+----+-------------+------------+--------+------+------------------------------+

The JOIN now adds all the IDs which are greater or equal than our random value and selects only the direct neighboor if a direct match is not possible. BUT as soon as one row is found, we stop (the LIMIT 1). And we read the rows according to the index (ORDER BY id ASC). As we are using >= instead of a = we can get rid of a the CEIL and get the same result with a little less work.

Equal Distribution

As soon as the distribution of the IDs is not equal anymore our selection of rows isn't really random either.

> select * from holes;
+----+----------------------------------+----------+
| id | name | accesses |
+----+----------------------------------+----------+
| 1 | d12b2551c6cb7d7a64e40221569a8571 | 107 |
| 2 | f82ad6f29c9a680d7873d1bef822e3e9 | 50 |
| 4 | 9da1ed7dbbdcc6ec90d6cb139521f14a | 132 |
| 8 | 677a196206d93cdf18c3744905b94f73 | 230 |
| 16 | b7556d8ed40587a33dc5c449ae0345aa | 481 |
+----+----------------------------------+----------+

The RAND function is generating IDs like 9 to 15 which all lead to the id 16 to be selected as the next higher number.

There is no real solution for this problem, but your data is mostly constant you can add a mapping table which maps the row-number to the id:

> create table holes_map ( row_id int not NULL primary key, random_id int not null);
> SET @id = 0;
> INSERT INTO holes_map SELECT @id := @id + 1, id FROM holes;
> select * from holes_map;
+--------+-----------+
| row_id | random_id |
+--------+-----------+
| 1 | 1 |
| 2 | 2 |
| 3 | 4 |
| 4 | 8 |
| 5 | 16 |
+--------+-----------+

The row_id is now free of holes again and we can run our random query again:

SELECT name FROM holes
JOIN (SELECT r1.random_id
FROM holes_map AS r1
JOIN (SELECT (RAND() *
(SELECT MAX(row_id)
FROM holes_map)) AS row_id)
AS r2
WHERE r1.row_id >= r2.row_id
ORDER BY r1.row_id ASC
LIMIT 1) as rows ON (id = random_id);

After 1000 fetches we see a equal distribution again:

> select * from holes;
+----+----------------------------------+----------+
| id | name | accesses |
+----+----------------------------------+----------+
| 1 | d12b2551c6cb7d7a64e40221569a8571 | 222 |
| 2 | f82ad6f29c9a680d7873d1bef822e3e9 | 187 |
| 4 | 9da1ed7dbbdcc6ec90d6cb139521f14a | 195 |
| 8 | 677a196206d93cdf18c3744905b94f73 | 207 |
| 16 | b7556d8ed40587a33dc5c449ae0345aa | 189 |
+----+----------------------------------+----------+

Multiple Rows at once

If you want to get more than one row returned, you can:

  • execute the Query several times
  • write a stored procedure which is executing the query and stores the result in a temp-table
  • (make a UNION)[http://jan.kneschke.de/2007/2/22/analyzing-complex-queries]

Performance

Now let's see what happends to our performance. We have 3 different queries for solving our problems.

  • Q1. ORDER BY RAND()
  • Q2. RAND() * MAX(ID)
  • Q3. RAND() * MAX(ID) + ORDER BY ID

Q1 is expected to cost N * log2(N), Q2 and Q3 are nearly constant.

The get real values we filled the table with N rows ( one thousand to one million) and executed each query 1000 times.

100        1.000      10.000     100.000    1.000.000
Q1 0:00.718s 0:02.092s 0:18.684s 2:59.081s 58:20.000s
Q2 0:00.519s 0:00.607s 0:00.614s 0:00.628s 0:00.637s
Q3 0:00.570s 0:00.607s 0:00.614s 0:00.628s 0:00.637s

As you can see the plain ORDER BY RAND() is already behind the optimized query at only 100 rows in the table.

A more detailed analysis of those queries is at analyzing-complex-queries.

 

Tags: mysql, order, rand, explain, analyze