Firefox下回退时form表单重新提交的问题

   曾经写过一个javascript自动常见form,并提交到自动创建的iframe的一个应用。由于提交之后跳转到另外一个页面,然后回退,会返现form的提交请求又自动重发了一次,因为是提交到一个隐形的iframe中的,我就在提交之后把iframe给删除了,但是回退后还会重新发送提交请求,我没有办法,知道有一天我在走路的时候,突然想到问题可能出现在为删除的form上,于是,我测试了一个,提交form之后就删除form,然后回退就没有该问题了,困扰了我几个月的问题终于真相大白、水落石出了。

关于浏览器的访问限制

1.  跨域访问是浏览器非常明显的访问限制
2. 另外除了根据域名的访问限制外,还有协议间的限制,如:http 和 https即使是同域也不能相互访问;

我原来以为跨域限制应该不限制http和https之间的访问,知道做的时候才发现是有这方面的限制的。做浏览器这方面开发是需要更多地了解浏览器的特性的。

PHP 中的内存限制


   今天在做图片上传部分的工作,上传后的图片需要做处理,a机器上总报PHP内存耗尽的错误,检查了一下php.ini里面memory_limit 设置为16M,应该够用了吧,才处理2M的图片;后来检查了一下处理图片需要很大内存的,如果图片尺寸很大的话,即使图片占用空间不大,处理起来也很费内存的;2M的图片需要50多M的内存。
   但是奇怪的是,在b机器上处理图片就没有问题,而b机器上php.ini 的设置为:
   memory_limit = 8M ;
   这就奇怪了,然后使用 php -r "echo ini_get(‘memory_limit’);"  , 在 a机器上显示结果为: 16M ,在b机器上没有显示;
   于是,怀疑b机器上的
memory_limit没有生效;问了一下百度,才知道要是memory_limit生效,则PHP在编译的时候需要 –enable-memory-limit ; 于是查了一下a机器和b机器上的编译选项,都没有明确指定 –enable-memory-limit ;
   在用php -v 查看一下,
   a机器版本php 5.2.5
   b机器版本php 5.1.5
   大概是默认的编译选项不同吧! 看了一下PHP 5.2.5 的NEWS ,果然PHP 5.2.5默认是开启的,而PHP 5.1.5 默认是不开启的。

启发
   我们在给PHP添加内存限制是只是在php.ini中添加了 memory_limit 的设置,却没有验证是否达到了效果;
   这就教育我们做事要“善始善终”, 不能只是做完了就算完了,一定要想办法证明自己做的没有问题,否则事情就没有做完。

mc_watch

本文是一个查看mc的PHP脚本文件,用法简单。

 

javascript 中的类属性与实例属性

下面的代码实现了javascript中类属性与实例属性:

function myObject() {
    var 
instance_data 100;
    
this.getInstanceData = function() {
        return 
instance_data;
    }
     
this.setInstanceData = function(v) {
        
instance_data v;
     }
}

// 使用一个匿名函数去修改构造器的原型 myObject.prototype, 以访问该匿名函数中的upvalue
void function() {
    var 
class_data 10;
    
this.getClassData = function() {
        return 
class_data;
    }
    
this.setClassData = function(v) {
        
class_data v;
    }
}.
call(myObject.prototype);

// 创建对象
//
var obj1 = new myObject();
var 
obj2 = new myObject();

obj1.setInstanceData(10);
alert(obj2.getInstanceData()); // 输出100

obj1.setClassData(200);
alert(obj2.getClassData()); // 输出200

Javascript 中构造单实例

下面几段代码,比较耐人寻味,里面体现了一些javascript的运行本质的东西,需要慢慢理解:

function aFunc() {
    function 
myfunc() {
        
//...
    
}
    return 
myfunc;
}
var 
f1 aFunc();
var 
f2 aFunc();
alert(f1 === f2); //false

function aFunc2() {
    var 
myfunc = function() {
        
//...
    
}
    return 
myfunc;
}
var 
f1 aFunc2();
var 
f2 aFunc2();
alert(f1 === f2); // false

function aFunc3() {
    function 
myfunc() {
        
//...
    
}
    return function () {
        return 
myfunc;
    }
}

var f1 aFunc3();
var 
f2 aFunc3();
alert(f1 === f2); // false

var aFunc4 = function () {
    function 
myfunc() {
        
//...
    
}
    return function () {
        return 
myfunc;
    }
}();
var 
f1 aFunc4();
var 
f2 aFunc4();
alert(f1 === f2); // true

一个不错的debug函数

摘自:PHP手册

通过debug_backtrace()函数可以找到

<?php
// useful and comfortable debug function
// it's show memory usage and time flow between calls, so we can quickly find a block of code that need optimisation...
// example result:
/*
debug example.php> initialize
debug example.php> code-lines: 39-41 time: 2.0002 mem: 19 KB
debug example.php> code-lines: 41-44 time: 0.0000 mem: 19 KB
debug example.php> code-lines: 44-51 time: 0.6343 mem: 9117 KB
debug example.php> code-lines: 51-53 time: 0.1003 mem: 9117 KB
debug example.php> code-lines: 53-55 time: 0.0595 mem: 49 KB
 */

function debug()
{
   static 
$start_time NULL;
   static 
$start_code_line 0;

   $call_info array_shiftdebug_backtrace() );
   
$code_line $call_info['line'];
   
$file array_popexplode('/'$call_info['file']));

   if( $start_time === NULL )
   {
       print 
"debug ".$file."> initializen";
       
$start_time time() + microtime();
       
$start_code_line $code_line;
       return 
0;
   }

   printf("debug %s> code-lines: %d-%d time: %.4f mem: %d KBn"$file$start_code_line$code_line, (time() + microtime() - $start_time), ceilmemory_get_usage()/1024));
   
$start_time time() + microtime();
   
$start_code_line $code_line;
}

////////////////////////////////////////////////
// example:

debug();
sleep(2);
debug();
// soft-code...
$a 5;
debug();

// hard-code
for( $i=0$i<100000$i++)
{
   
$dummy['alamakota'.$i] = 'alamakota'.$i;
}
debug();
usleep(100000);
debug();
unset(
$dummy);
debug();

?>