小编Chr*_*ris的帖子

file_get_contents => PHP致命错误:允许的内存耗尽

我在处理大文件时没有经验,所以我不知道该怎么做.我试图使用file_get_contents读取几个大文件; 任务是使用preg_replace()清理和消除它们.

我的代码在小文件上运行良好; 但是,大文件(40 MB)会触发内存耗尽错误:

PHP Fatal error:  Allowed memory size of 16777216 bytes exhausted (tried to allocate 41390283 bytes)
Run Code Online (Sandbox Code Playgroud)

我正在考虑使用fread(),但我不确定它是否也能正常工作.这个问题有解决方法吗?

感谢您的输入.

这是我的代码:

<?php
error_reporting(E_ALL);

##get find() results and remove DOS carriage returns.
##The error is thrown on the next line for large files!
$myData = file_get_contents("tmp11");
$newData = str_replace("^M", "", $myData);

##cleanup Model-Manufacturer field.
$pattern = '/(Model-Manufacturer:)(\n)(\w+)/i';
$replacement = '$1$3';
$newData = preg_replace($pattern, $replacement, $newData);

##cleanup Test_Version field and create comma delimited layout. …
Run Code Online (Sandbox Code Playgroud)

php

24
推荐指数
2
解决办法
5万
查看次数

CDATA是什么意思?

大师,

我是自学成才的.有很多你开明的人称之为基本的,我一无所知.

阅读这个 jQuery教程,我注意到了这个标签(缺少更好的单词):"CDATA"如此处所示(从顶部开始的第三行):

<script src="http://jquery.com/src/jquery-latest.js"></script>
<script> 
//<![CDATA[    
$(document).ready(function(){
$(".article .thebody").hide();
$("#container .article ul")
       .prepend("<li class='readbody'><a href='' title='Read the article'>Read Body</a></li>");

$(".actions li.readbody a").click(function(event){
$(this).parents("ul").prev(".thebody").toggle();
event.preventDefault();
     });
   });
//]]></script>
Run Code Online (Sandbox Code Playgroud)

CDATA是什么意思?有没有类似CDATA的标签?

xml jquery cdata

17
推荐指数
1
解决办法
7284
查看次数

两个表的索引名称相同

我正在为我们的团队构建一个小的Mysql数据库.对于我的数据库中的两个表,我使用了相同的索引名称.

是否有任何性能损失?

我做了一些测试查询(800,000多行)到目前为止,非常好.

mysql

6
推荐指数
1
解决办法
5434
查看次数

捕获远程脚本的退出代码?

我有一个每天在我的服务器上运行的shell脚本.它做一些房屋清洁并连接到远程主机以执行其他任务,即

#!/bin/bash

#do something...
...locally...

#run remote script...
ssh user@remotehost "/opt/process/verify.sh"

exit
Run Code Online (Sandbox Code Playgroud)

它工作正常但是为了安全我想捕获(如果可能)来自"/opt/process/verify.sh"的返回码,即

  • 如果失败,返回"1"并发送电子邮件给管理员
  • 如果成功,返回"0"并向开发人员发送电子邮件.

我开始阅读有关命令的内容trap.我可以将它用于此目的吗?还有其他选择吗?

ssh bash

6
推荐指数
3
解决办法
9118
查看次数

将shell参数传递给awk不起作用

为什么这样做

for myfile in `find . -name "R*VER" -mtime +1`
do
   SHELLVAR=`grep ^err $myfile || echo "No error"`
   ECHO $SHELLVAR
done
Run Code Online (Sandbox Code Playgroud)

和产出

No error
err ->BIST Login Fail 3922 err 
No error
err ->IR Remote Key 1 3310 err 
Run Code Online (Sandbox Code Playgroud)

但事实并非如此

for myfile in `find . -name "R*VER" -mtime +1`
do
   SHELLVAR=`grep ^err $myfile || echo "No error"`
   awk -v awkvar=${SHELLVAR} '{print awkvar}'
done
Run Code Online (Sandbox Code Playgroud)

和产出

awk: cmd. line:1: fatal: cannot open file `{print awkvar}' for reading (No such file or directory) …
Run Code Online (Sandbox Code Playgroud)

bash awk

4
推荐指数
2
解决办法
4283
查看次数

测试数值?

我们在临时表中加载的供应商数据相当脏.一列特别捕获数字数据,但40%的时间具有垃圾字符或随机字符串.

我必须创建一个过滤掉该列中值范围的报告.所以,我尝试使用替换/翻译这样的组合

select replace(translate(upper(str),' ','all possible char'),' ','')
from table
Run Code Online (Sandbox Code Playgroud)

但是只要它遇到我没有编码的字符就会失败.因此,报告永远不会自动化.

Javascript具有isNaN()函数来确定值是否为非法数字(如果是,则为True,否则为false).

我怎么能用DB2做同样的事情?你有什么主意吗?

提前致谢.

db2

3
推荐指数
1
解决办法
2万
查看次数

计算文件的最快方法是什么?

我们刚刚安装了一个大型文件管理器设备,我们想要存储来自供应商的数据.他们每天都在FTP文件,现在,我们有大约60,000多个文件.

find . -name '*TXT' -exec ls '{}' \; | wc -l尽管做得很慢但也会工作.

有更快的方法来计算文件吗?

bash

3
推荐指数
1
解决办法
216
查看次数

在表中折叠/展开div?

几天前,我问了一个关于折叠div的问题([link text] [fold-unfold div]).我得到的答案让我在编码方面取得了很大的进步.但是,我的要求已经改变了.

作为一个新手与所有这些网络的东西,我虽然用表和表头包装div很容易.男孩,我错了.

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Animate my Div</title>
<style type="text/css" media="screen">
a            {text-decoration: none; color: black; }
#expand      {background-color: #fff;}
.description {display: none;         }
.entry       {margin: 0; padding: 0px;}
</style>
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".entry a").click(function() {
    $(this).parents('.entry').find('.description').slideToggle(1000);
});
});
</script>
</head>
<body>
<?php
$con = mysql_connect("korg", "joe", "bob");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("wfr11", $con);
$result = mysql_query("
select title,description from webcases"); …
Run Code Online (Sandbox Code Playgroud)

html php jquery html-table fold

2
推荐指数
1
解决办法
3266
查看次数

查找和天数范围

我试图在bash中编写一个归档脚本,但我似乎无法让find()使用一个天数的间隔.

我需要编码的范围是

  1. 文件最后修改在今天和31天之间.这有效:

find . -name "*.VER" -mtime -31 -exec mv '{}' /opt/html/31';' -print

  1. 文件最后修改时间为31天到62天之间.这不起作用:

find . -name "*.VER" -mtime -31 -mtime -62 -exec mv '{}' /opt/html/62 ';' -print

  1. 文件最后修改时间为62天到93天之间
  2. 文件最后修改时间为93天到124天之间
  3. ......你明白了(最多一年)......

有没有办法编写我的find()命令来使用多天的范围?

bash find

2
推荐指数
1
解决办法
4164
查看次数

DB2日期时间值的字符串表示形式的语法不正确

我们有一个临时表,用于从供应商处加载原始数据.

一列用于捕获时间戳,但其数据类型为varchar(265).数据很脏:大约有40%的时间存在垃圾数据,否则就会出现像这样的时间戳数据

2011/11/15 20:58:48.041 
Run Code Online (Sandbox Code Playgroud)

我必须创建一个报告,过滤掉该列的某些日期/时间戳,但在我尝试投射它的地方,我收到一个错误:

db2 => select cast(loadedon as timestamp) from automation

1
--------------------------
SQL0180N  The syntax of the string representation of a datetime value is incorrect.  SQLSTATE=22007
Run Code Online (Sandbox Code Playgroud)

为解析/转换时间戳字符串,我需要做什么?

db2 timestamp casting

2
推荐指数
1
解决办法
3万
查看次数

标签 统计

bash ×4

db2 ×2

jquery ×2

php ×2

awk ×1

casting ×1

cdata ×1

find ×1

fold ×1

html ×1

html-table ×1

mysql ×1

ssh ×1

timestamp ×1

xml ×1