首页 \ 问答 \ PHP在后台进程完成后启动脚本?(PHP Launch script after background process completes?)

PHP在后台进程完成后启动脚本?(PHP Launch script after background process completes?)

我正在用PDF2SWF转换PDF并用XPDF索引..用exec ..只有这样才需要执行时间非常高。

是否有可能将其作为后台进程运行,然后在完成转换后启动脚本?


I am converting a PDF with PDF2SWF and Indexing with XPDF.. with exec.. only this requires the execution time to be really high.

Is it possible to run it as background process and then launch a script when it is done converting?


原文:https://stackoverflow.com/questions/2414498
更新时间:2023-05-17 06:05

最满意答案

从Java 5中的ArrayList开始,如果数组具有正确的大小(或更大),则该数组将被填充。 所以

MyClass[] arr = myList.toArray(new MyClass[myList.size()]);

将创建一个数组对象,填充它并将其返回到“arr”。 另一方面

MyClass[] arr = myList.toArray(new MyClass[0]);

将创建两个数组。 第二个是长度为0的MyClass数组。因此,对象的对象创建将立即被抛出。 就源代码而言,编译器/ JIT不能优化这个,因此它不会被创建。 另外,使用零长度对象会导致toArray() - 方法中的转换。

看到ArrayList.toArray()的源码:

public <T> T[] toArray(T[] a) {
    if (a.length < size)
        // Make a new array of a's runtime type, but my contents:
        return (T[]) Arrays.copyOf(elementData, size, a.getClass());
    System.arraycopy(elementData, 0, a, 0, size);
    if (a.length > size)
        a[size] = null;
    return a;
}

使用第一种方法,以便只创建一个对象并避免(隐含但仍然昂贵)的铸件。


Counterintuitively, the fastest version, on Hotspot 8, is:

MyClass[] arr = myList.toArray(new MyClass[0]);

I have run a micro benchmark using jmh the results and code are below, showing that the version with an empty array consistently outperforms the version with a presized array. Note that if you can reuse an existing array of the correct size, the result may be different.

Benchmark results (score in microseconds, smaller = better):

Benchmark                      (n)  Mode  Samples    Score   Error  Units
c.a.p.SO29378922.preSize         1  avgt       30    0.025 ▒ 0.001  us/op
c.a.p.SO29378922.preSize       100  avgt       30    0.155 ▒ 0.004  us/op
c.a.p.SO29378922.preSize      1000  avgt       30    1.512 ▒ 0.031  us/op
c.a.p.SO29378922.preSize      5000  avgt       30    6.884 ▒ 0.130  us/op
c.a.p.SO29378922.preSize     10000  avgt       30   13.147 ▒ 0.199  us/op
c.a.p.SO29378922.preSize    100000  avgt       30  159.977 ▒ 5.292  us/op
c.a.p.SO29378922.resize          1  avgt       30    0.019 ▒ 0.000  us/op
c.a.p.SO29378922.resize        100  avgt       30    0.133 ▒ 0.003  us/op
c.a.p.SO29378922.resize       1000  avgt       30    1.075 ▒ 0.022  us/op
c.a.p.SO29378922.resize       5000  avgt       30    5.318 ▒ 0.121  us/op
c.a.p.SO29378922.resize      10000  avgt       30   10.652 ▒ 0.227  us/op
c.a.p.SO29378922.resize     100000  avgt       30  139.692 ▒ 8.957  us/op

For reference, the code:

@State(Scope.Thread)
@BenchmarkMode(Mode.AverageTime)
public class SO29378922 {
  @Param({"1", "100", "1000", "5000", "10000", "100000"}) int n;
  private final List<Integer> list = new ArrayList<>();
  @Setup public void populateList() {
    for (int i = 0; i < n; i++) list.add(0);
  }
  @Benchmark public Integer[] preSize() {
    return list.toArray(new Integer[n]);
  }
  @Benchmark public Integer[] resize() {
    return list.toArray(new Integer[0]);
  }
}

You can find similar results, full analysis, and discussion in the blog post Arrays of Wisdom of the Ancients. To summarize: the JVM and JIT compiler contains several optimizations that enable it to cheaply create and initialize a new correctly sized array, and those optimizations can not be used if you create the array yourself.

相关问答

更多
  • 定义一个字符串类型数组ss,大小为list的大小。定义一个泛型 数组obj,数组内容为list的内容。用一个for循环一次在控制台打印出obj数组的内容。
  • Object[] toArray() 按适当顺序(从第一个到最后一个元素)返回包含此列表中所有元素的数组。 T[] toArray(T[] a) 按适当顺序(从第一个到最后一个元素)返回包含此列表中所有元素的数组;返回数组的运行时类型是指定数组的运行时类型。
  • self范围: 在类定义中, self始终是class constants(instance of Class)本身。(实例方法除外)。 在实例方法中, self是该类常量的实例,它只调用相应的方法。 p RUBY_VERSION class Foo def self.talk p "here SELF is-> #{self}" end def display p "here SELF is-> #{self}" end p "here SE ...
  • 没有太多差异,但这里有一些: class myClass extends myClass2 现在,这可能不是那么有问题,因为有myFunction.prototype = Object.create(myFunction2); ,但是,它可能有点复杂。 浏览器支持。 ECMAScript 6引入了类,但构造函数有多长时间了? 当然,相当长的一段时间。 某些浏览器可能不支持类。 总而言之,在我看来,你应该使用构造函数来支持浏览器。 但是如果你要在遥远的未来某个时候编写代码 - 类更整洁,更容易阅读。 Ther ...
  • 从Java 5中的ArrayList开始,如果数组具有正确的大小(或更大),则该数组将被填充。 所以 MyClass[] arr = myList.toArray(new MyClass[myList.size()]); 将创建一个数组对象,填充它并将其返回到“arr”。 另一方面 MyClass[] arr = myList.toArray(new MyClass[0]); 将创建两个数组。 第二个是长度为0的MyClass数组。因此,对象的对象创建将立即被抛出。 就源代码而言,编译器/ JIT不能优 ...
  • 为您的课程实施自定义适配器: public class MyClassAdapter extends ArrayAdapter { private static class ViewHolder { private TextView itemView; } public MyClassAdapter(Context context, int textViewResourceId, ArrayList items) { ...
  • 可能你应该看看Grasshopper并且不要重新发明轮子。 它是一个MSIL到Java字节码编译器,它是一个成熟的产品。 Probably you should have a look at Grasshopper and don't reinvent the wheel. It's a MSIL to Java bytecode compiler and it's a mature product.
  • 是否保证数组的最后4个元素始终为null? 基本上没有。 数组的最后四个元素将保留其先前的值。 如果该值恰好为null ,则它们将保持为null 。 例如: Integer[] array = Stream.of(7, 8).parallel().toArray(i -> new Integer[] {1, 2, 3, 4, 5, 6}); System.out.println(Arrays.toString(array)); 输出: [7, 8, 3, 4, 5, 6] 是否有可能必须使用toArr ...
  • 第一个调用复制构造函数,临时对象作为参数 - MyClass()创建临时对象。 第二个调用默认构造函数。 实际上,在大多数情况下,它们被优化为相同的代码,但这是语义上的差异。 正如Negal所说,案件与POD类型略有不同; 当“MyClass”是POD时,第二个片段不会对mc值初始化,而首先是。 The first invokes copy constructor, with temporary object as parameter - MyClass() creates temporary. The s ...
  • 实际上它根本不是指同一个类。 实际上,第二个EmployeeData不引用任何类。 这是通用名称。 您的ODataProxy定义了一个方法: public virtual IEnumerable GetList(string query); ODataProxyStub使用以下ODataProxyStub实现: public override IEnumerable GetList(string query) 这不是 EmployeeD ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。