分页: 2/74 第一页 上页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]
在NSDictionary里用objectAtIndex方法不行,报错,查得此招:

Enumerating all the Keys and Values

Sometime, you need to iterate over all the key/value pairs in a dictionary. To do this, you use the method -allKeys to retrieve an array of all the keys in the dictionary; this array contains all the keys, in no particular (ie random) order. You can then cycle over this array, and for each key retrieve its value. The following example prints out all the key-values in a dictionary:

void describeDictionary (NSDictionary *dict)
{
  NSArray *keys;
  int i, count;
  id key, value;

  keys = [dict allKeys];
  count = [keys count];
  for (i = 0; i < count; i++)
  {
    key = [keys objectAtIndex: i];
    value = [dict objectForKey: key];
    NSLog (@"Key: %@ for value: %@", key, value);
  }
}


As usual, this code is just an example of how to enumerate all the entries in a dictionary; in real life, to get a description of a NSDictionary, you just do NSLog (@"%@", myDictionary);.

原文:http://www.gnustep.it/nicola/Tutorials/BasicClasses/node27.html
Tags:
要配置一个postfix发邮件,需要以 xx@test.aslibra.com 发送邮件
同时提供smtp服务给局域网其它服务器提供发送邮件服务

安装好postfix后,可以参考如下配置文件(去掉注释内容):

/etc/postfix/main.cf

myhostname = test.aslibra.com
mydomain = test.aslibra.com
mynetworks = 192.168.1.0/24, 127.0.0.0/8
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
mail_owner = postfix
myorigin = $myhostname
inet_interfaces = all
unknown_local_recipient_reject_code = 550
relay_domains = $mydestination
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
debug_peer_level = 2
debugger_command =
   PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
   xxgdb $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.3.3/samples
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES


PHP发送邮件可以使用phpmailer

include('libraries/class.phpmailer.php');

$mail = new PHPMailer();  
$mail->CharSet="UTF-8";
$mail->IsSMTP();                            // 经smtp发送  
$mail->Host     = $this->smtp_ip;           // SMTP 服务器  
$mail->SMTPAuth = false;          // 局域网不需要SMTP 认证  
$mail->From     = $from;  // 发信人  
$mail->FromName = $fromuser;        // 发信人别名  
$mail->Sender = $from;

$mail->AddAddress($to);  // 收信人  
if(isset($ccmail)){  
  $mail->AddCC($ccmail);  // cc收信人
}  
if(isset($bccmail)){  
  $mail->AddCC($bccmail);    // bcc收信人
}  

$mail->WordWrap = 50;  
$mail->IsHTML(true);                            // 以html方式发送  
$mail->Subject  = $title;                 // 邮件标题  
$mail->Body     = $content;                    // 邮件内空  

$mail->Send();


扩展阅读:

1 带smtp认证的postfix配置
http://hi.baidu.com/jedibd/blog/item/7b73ab25a7b7e06d35a80f45.html
2 CentOS下(PostFix)SMTP服务器的构建
http://www.fuancn.cn/html/ServerSettings/Linux/CentOS/20084288.html
3 phpmailer,smtp发送邮件实例
http://blog.51yip.com/php/910.html/comment-page-1
4 postfix邮件服务的基本配置
http://eastwalk.blogbus.com/logs/57585048.html
5 Postfix服务的基本配置
http://book.51cto.com/art/200904/118655.htm
6 telnet smtp发邮件
http://hi.baidu.com/guixiao_zhou/blog/item/49f8a73259a9f2210a55a9ec.html
7 簡易 Mail Server 架設 -- Postfix 設定
http://linux.vbird.org/linux_server/0390postfix.php
Tags: , ,
[转] 事情是这个样儿的,折腾了好几天就是搞不明白为啥设置了.ssh目录,在authorized_keys设置了key后登录还提示需要输入密码。捞干的,说怎么解决吧,注意权限,.ssh权限700,authorized_keys权限600,就OK啦!~~~~

chmod 700 ~/.ssh/
chmod 700 ~
chmod 600 ~/.ssh/authorized_keys


---------------------

一直很困惑要求输入密码,原来是不知道哪个操蛋的把root文件夹改777

drwxrwxrwx  11 root    root     4096 Nov 10 22:52 root

另外一个机器被改归属人,操蛋的

drwx------   7 mysql mysql 36864 10-26 15:03 root

参考:http://my.oschina.net/shootercn/blog/15418
Tags:
SAS硬盘可以热插拔,插入硬盘后,磁盘会立刻显示在fdisk -l 的列表里,可以立刻开始使用。
SCSI硬盘还没这么便捷,但也是可以做到不重启就加入使用的。

这里关系最大的是 /proc/scsi/scsi 文件
在linux系统里, /proc 的内容是系统运行状态等信息
修改它会导致立刻生效,比如支持包转发

目前服务器在用的硬盘有两个,分别插在0和1的插槽
加入的四个硬盘分别插到3-5的插槽
IBM的机器硬盘盒的螺丝凸起的,安装到DELL的硬盘盒里,有点凸起
插入机器里会有点紧,但可以正常使用

我们先看看 /proc/scsi/scsi的文件
[root@aslibra.com ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: SEAGATE  Model: ST3146707LC      Rev: D703
  Type:   Direct-Access                    ANSI SCSI revision: 03
Host: scsi0 Channel: 00 Id: 01 Lun: 00
  Vendor: SEAGATE  Model: ST3146707LC      Rev: D703
  Type:   Direct-Access                    ANSI SCSI revision: 03
Host: scsi0 Channel: 00 Id: 06 Lun: 00
  Vendor: PE/PV    Model: 1x6 SCSI BP      Rev: 1.0
  Type:   Processor                        ANSI SCSI revision: 02


操作方法:
引用
我们以root权限执行 echo "scsi add-single-device 0 0 1 0" > /proc/scsi/scsi  添加scsi设备

解释一下 scsi add-single-device a b c d 这个指令中的参数:                        
# 相反  scsi remove-single-device a b c d 是用来移除设备的

a ------- Host 是硬盘所在的SCSI控制器的编号,这里只有一个控制器,所以为0
b ------- Channel 硬盘所在SCSI通道的编号,这里是单通道,为0
c ------- Id 硬盘的SCSI ID号,就是插入的硬盘插槽编号,
d ------- Lun ,硬盘的lun号[logical unit number]即逻辑单元号,指的是一个用于SCSI总线的唯一的识别号,
          总线使它能区别其他八个设备(它们每个都是一个逻辑单元)。


比较一下上面的内容和scsi文件的内容,我们可以知道,添加第三个插槽的硬盘是这么操作的:
[root@aslibra.com ~]# echo "scsi add-single-device 0 0 2 0" > /proc/scsi/scsi
[root@aslibra.com ~]# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: SEAGATE  Model: ST3146707LC      Rev: D703
  Type:   Direct-Access                    ANSI SCSI revision: 03
Host: scsi0 Channel: 00 Id: 01 Lun: 00
  Vendor: SEAGATE  Model: ST3146707LC      Rev: D703
  Type:   Direct-Access                    ANSI SCSI revision: 03
Host: scsi0 Channel: 00 Id: 06 Lun: 00
  Vendor: PE/PV    Model: 1x6 SCSI BP      Rev: 1.0
  Type:   Processor                        ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 02 Lun: 00
  Vendor: IBM-ESXS Model: MAP3147NC     FN Rev: C101
  Type:   Direct-Access                    ANSI SCSI revision: 03


ifdisk -l 也可以看到此硬盘了,说明已经可以使用了
把 0 0 2 0换成0 0 3 0可以如此类似的增加余下的scsi硬盘,操作完毕!
Tags: ,
如果你访问不到一个网站,那可能是如下问题:

1 本地网络故障

你如果确认可以正常访问别的网站,比如百度,新浪,那基本可以排除此故障

2 对方网站故障

ping域名,一般会解析出一个ip,如果ping不通,那可能是对方网站故障
如果网站做了防火墙规则,可能ping不到,那至少试试 telnet 域名 80 会有反应的
如果可能,把ip范围放大一些,确认该网段是否正常

3 域名解析故障

如果ping没有返回ip值,试试dig命令或者nslookup,确认是否返回ip结果

4 域名污染

部分域名被监管了,可能会强制把域名解析到无效的ip地址,比如国外的某些网站
dig可以检查一下,一般会稳定解析为某个ip一段时间,如果经常变化,那肯定是有问题了,比如脸书网

5 被封了80端口或者被重置

那。。 没辙啦

6 ip访问被封锁

那。。 也没辙啦
Tags:
php的日志是值得关注的,包含错误日志和慢日志

一 错误输出

找到php.ini
log_errors = On

; Log errors to specified file.
error_log = /Data/logs/php/error.log


比如会捕获到类似信息:

[23-Oct-2011 17:17:41] PHP Fatal error:  Class 'Strclass' not found in /Data/webapps/www.aslibra.com/application/errors/error_404.php on line 11

这个有助于分析被访问的页面发生的致命错误或者是警告

二 慢日志

慢日志和数据库的慢查询有点类似,会记录下来执行超过多少时间的php执行的内容
这个如果是用fast-cgi的话,可以在fpm的配置里面有

      The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
      '0s' means 'off'
      <value name="request_slowlog_timeout">10s</value>

      The log file for slow requests
      <value name="slowlog">/Data/logs/php/slow.log</value>


比如上面是记录超过10秒的php,记录在相应的文件里
你可以拿到类似的日志:

Oct 23 23:00:20.528849 pid 11586 (pool default)
script_filename = /www.aslibra.com/index.php
[0x00007fffae1869e0] mysql_query() /www.aslibra.com/system/database/drivers/mysql/mysql_driver.php:163
[0x00007fffae186bb0] _execute() /www.aslibra.com/system/database/DB_driver.php:453
[0x00007fffae186eb0] simple_query() /www.aslibra.com/system/database/DB_driver.php:299
[0x00007fffae1870b0] query() /www.aslibra.com/v3/models/myuser.php:51
[0x00007fffae1872a0] get_users_by_uids() /www.aslibra.com/v3/models/myuser.php:58
[0x00007fffae187580] get_users() /www.aslibra.com/v3/controllers/pic.php:134
[0x00007fffae187870] experience() /www.aslibra.com/v3/controllers/pic.php:349
[0x00007fffae187940] user() unknown:0
[0x00007fffae187cf0] call_user_func_array() /www.aslibra.com/system/core/CodeIgniter.php:297
[0x00007fffae187f40] +++ dump failed


日志里包含的信息:执行时间,访问入口,执行的函数的顺序和所有父级调用关系
比如这里可以获知是数据库查询时出现过慢,调用关系也一目了然,可以去排查跟踪了
Tags:
注:分析html的好东西

最近想用php写一个爬虫,就需要解析html,在sourceforge上找到一个项目叫做PHP Simple HTML DOM Parser,它可以以类似jQuery的方式通过css选择器来返回指定的DOM元素,功能十分强大。

首先要在程序的开始引入simple_html_dom.php这个文件

include_once('simple_html_dom.php');

PHP Simple HTML DOM Parser提供了3种方式来创建DOM对象
Tags: ,
分页: 2/74 第一页 上页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐