开发者

php exec memory usage with phing

I'm automating some tasks using phing and yui compressor and I'm running into a memory problem. I'm curious if there is a better way to handle this.

Part of phing build script

<target name="finalize">
  <property name="cssfolders" value="folder1, folder2, folder3" />
  <foreach list="${cssfolders}" param="dir" target="minifyCSS" />

  <property name="jsfolders" value="folder1, folder2, folder3" />
  <foreach list="${jsfolders}" param="dir" target="minifyJS" />
</target>

<target name="minifyCSS">
  <exec command="find ${dir}/dev -name '*.css' -exec basename {} \; | while read file; do java -jar ${yuiCompressor} -o ${dir}/prod/$file ${dir}/dev/$file; done" />
</target>

<target name="minifyJS">
  <exec command="find ${dir}/dev -name '*.js' -exec basename {} \; | while read file; do java -jar ${yuiCompressor} -o ${dir}/prod/$file ${dir}/dev/$file; done" />
</target>

If I split up the finalize target into two, one for css and one for js - then 开发者_如何学JAVAthe script will work. But when I keep them combined I have a problem. Before everyone says to just split the target, which I'm ok with doing, I'm afraid as more JS files are added I'm going to eventually run into this problem again.

I'm curious if there is a better way to execute my plan w/out continuously monitoring and increasing php's memory usage. Perhaps a more efficient command to execute, or utilizing a php function that will allow me to use more memory or the disk if I exhaust allocated resources?

Side project - kudos to anyone who knows how to combine the minify targets into one. They are practically the same except I need to know what type of file to "find" for each one (css or js). If there is a way to handle this w/ only one target - I wanna know! :)


The only reason I can see this using so much memory is that the yuiCompressor is outputting a lot of information to stdout. This is then captured by the phing execute task.

Try calling the execute task with spawn parameter set to true which will cause it to redirect the stdout to /dev/null.

<exec command="find ${dir}/dev -name '*.css' -exec basename {} \; | while read file; do java -jar ${yuiCompressor} -o ${dir}/prod/$file ${dir}/dev/$file; done" spawn="true" />

As for the side project - maybe something like this would work:

<target name="finalize">
  <property name="cssfolders" value="css:folder1, css:folder2, css:folder3" />
  <foreach list="${cssfolders}" param="toCompress" target="minify" />

  <property name="jsfolders" value="js:folder1, js:folder2, js:folder3" />
  <foreach list="${jsfolders}" param="toCompress" target="minify" />
</target>

<target name="minify">
  <exec command="type=`echo ${toProcess}|cut -d ':' -f 1`;folder=`echo ${toProcess}|cut -d ':' -f 2`; find $folder/dev -name '*.'$type -exec basename {} \; | while read file; do java -jar ${yuiCompressor} -o $folder/prod/$file $folder/dev/$file; done" />
</target>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜