首页 \ 问答 \ Exec启动php作为后台进程(Exec to launch php as background process)

Exec启动php作为后台进程(Exec to launch php as background process)

我正在努力获取一个php文件,以使用PHP的exec()在后台运行。 作为第一个测试,我尝试过:

exec("ls -l > logfile.txt 2> errfile.txt &");

这工作正常。 logfile.txt获得一个目录列表。

按照php文档中的说明,由于exec启动了在后台运行的进程,标准输出(和标准错误)被重定向到一个文件。

现在,我试试

exec("/usr/bin/php -f /path/to/my.php > logfile.txt 2> errorfile.txt &");

它似乎没有任何反应。

这里是我正在尝试的测试文件:

alpha.php

<?php 
    $version="a"; 
    // Go do something we do not need to wait for. 
    exec("/usr/bin/php -f /path/to/beta.php > logfile.txt 2> errorfile.txt &"); 
?>

<html> 
    <head><title>Test</title></head> 
    <body> 
    <p>This is Alpha version <?php echo $version; ?></p> 
    </body> 
</html>

beta.php

<?php 
    if (!($fp = fopen('/home/johnst12/public_html/workshops/admin/betadata.txt', 'w'))) { exit;} 
    fprintf($fp, "Proof that Beta executed."); 
    fclose($fp); 
?>

如果我直接运行beta.php,它工作正常。 Betadata.txt获取消息。

如果我运行alpha.php来启动beta.php,则不会创建betadata.txt。 logfile.txt和errorfile.txt保持为空(预期)。

我确信php的路径和我的php文件的路径是正确的。

谷歌搜索澄清没有收获。 一些共同的主题似乎是(a)资源耗尽? (b)目标php文件没有权限? 资源似乎不太可能。 脚本的权限是全局读取644(rw-r - r--)。 我尝试添加执行(755)以防万一它会帮助。 它没有任何区别。

PHP版本5.3.21 Linux / Apache系统。 safe_mode关闭

我错过了什么? 谢谢。


I am struggling with getting a php file to run in the background with PHP's exec(). As a first test, I tried :

exec("ls -l > logfile.txt 2> errfile.txt &");

That works fine. logfile.txt gets filled with a directory listing.

Per instructions in the php documentation, since the exec kicks off a process that runs in the background, standard out (and standard error) are redirected to a file.

Now, I try

exec("/usr/bin/php -f /path/to/my.php > logfile.txt 2> errorfile.txt &");

It appears nothing happens.

Here are test files that I'm trying:

alpha.php

<?php 
    $version="a"; 
    // Go do something we do not need to wait for. 
    exec("/usr/bin/php -f /path/to/beta.php > logfile.txt 2> errorfile.txt &"); 
?>

<html> 
    <head><title>Test</title></head> 
    <body> 
    <p>This is Alpha version <?php echo $version; ?></p> 
    </body> 
</html>

beta.php

<?php 
    if (!($fp = fopen('/home/johnst12/public_html/workshops/admin/betadata.txt', 'w'))) { exit;} 
    fprintf($fp, "Proof that Beta executed."); 
    fclose($fp); 
?>

If I run beta.php directly, it works fine. Betadata.txt gets the message.

If I run alpha.php to launch beta.php, betadata.txt is not created. logfile.txt and errorfile.txt remain empty (expected).

I am sure that the path to php, and the path to my php file are correct.

Googling for clarification has not been fruitful. A couple of common themes seem to be (a) running out of resources? (b) lack of permission on the target php file? Out of resources seems unlikely. The permission on the script is global read 644 (rw-r--r--). I tried adding execute (755) just in case it would help. It made no difference.

PHP version 5.3.21 Linux/Apache system. safe_mode Off

What am I missing? Thanks.


原文:https://stackoverflow.com/questions/16290784
更新时间:2022-08-16 07:08

最满意答案

以下不是语法

<ArgType>genericMethod()

看起来类型参数必须在一个点之后

SomeClass.<ArgType>genericMethod()
this.<ArgType>genericMethod()
p.<ArgType>genericMethod()
super.<ArgType>genericMethod()
SomeClass.super.<ArgType>genericMethod()
SomeClass.this.<ArgType>genericMethod()

The following is not the syntax

<ArgType>genericMethod()

It seems the type arguments must come after a dot as in

SomeClass.<ArgType>genericMethod()
this.<ArgType>genericMethod()
p.<ArgType>genericMethod()
super.<ArgType>genericMethod()
SomeClass.super.<ArgType>genericMethod()
SomeClass.this.<ArgType>genericMethod()

相关问答

更多
  • 以下不是语法 genericMethod() 看起来类型参数必须在一个点之后 SomeClass.genericMethod() this.genericMethod() p.genericMethod() super.genericMethod() SomeClass.super.genericMethod() SomeClass.this.genericMethod() Th ...
  • 不要认为这是可能的,因为你只获得GenericType,而不是类的真正GenericArguments。 如果你看一下frame.GetMethod()。DeclaringType的返回,你会注意到,只有GenericType,而不是真正的GenericArguments都在调试结果中。 Don't think that this is possible, because you only get the GenericType, but not the real GenericArguments of t ...
  • 仅当方法调用中未指定泛型参数时,才会自动推断类型参数。 即,这个: myDto.ShouldHave<, RequiredAttribute, >(x => x.Id); 是无效的语法。 你可以“全有或全无”。 因此,如果要推断T和TT ,则需要以其他方式传递TV中当前包含的信息。 例如,一个选项是将属性的类型作为参数传递: public static void ShouldHave(this T obj, Expr ...
  • 在这种情况下,在setValue使用extends没有任何好处。 你是对的, setValue声明的T可以用它的上限E代替: public void setValue(E value) { this.value = value; } 但请考虑一下: public T setValueAndGiveItBack(T value) { this.value = value; return value; } 这意味着我们可以这样做: Double d = e ...
  • 在Constructor()方法中,您期望List类型,但是您提供了IEnumerable的实例。 将方法参数类型更改为IEnumerable 转换为查询到List类型 IEnumerable c = db .Products .Where(t => t.ProductID == p.ProductID) .SelectMany(s => s.Colors) .ToList(); if ( ...
  • 为什么编译器不会在Equals(object)方法上选择扩展方法? 只有在没有其他选择的情况下才考虑扩展方法。 这是一个回退 - 它不是正常重载分辨率的实例方法的一部分。 这不是特定于可空类型 - 它是正常扩展方法调用的一部分。 来自规范的第7.6.5.2节: 在一个表单的方法调用中 [...] 如果调用的正常处理未找到适用的方法 ,则会尝试将构造处理为扩展方法调用。 (强调我的。) Why does the compiler not choose the extension method over the ...
  • 根据你的意思,包括评论: 如果我在运行时尝试访问任何成员,它当然会抛出有关非现有成员的异常。 它听起来像编译器错误或JIT错误。 这意味着要对其进行诊断,我们需要您更多地了解您正在使用的编译器(确切版本)和/或您正在使用的JIT。 在编译器错误的情况下,如果您只是简单地显示已生成的IL,如果您熟悉它,则可能就足够了。 请注意,最新的VS预览包括一个全新的JIT(RyuJIT)并在系统范围内默认启用它 ,因此如果您已经安装了VS预览,那将是我的猜测。 如果是这样,你可以轻松地禁用它来检查。 注意这里的另一个选 ...
  • 如果返回类型必须保持Func则该方法必须保持通用。 您必须在编译时指定类型。 这就是事情 - 虽然PropertyInfo知道类型,但该信息仅在执行时可用,而编译器需要知道类型信息以检查您是否正确使用了该值等。它不可能知道什么属性的执行时间值将是。 如果您可以将返回类型更改为只有Expression那么您可以在执行时创建具有适当类型的Expression> ,但只需将其作为Expression返回。 如果没有强制转换,您将无法以编 ...
  • 使用通配符实例化泛型类型会生成编译错误,因为通配符表示任何类型 ,而实例化的ArrayList应具有具体类型。 通配符可用于变量或参数类型,但在创建泛型类型的实例时不能使用。 在本教程页面中也提到了这一点 : 在通用代码中,称为通配符的问号( ? )表示未知类型。 通配符可用于各种情况:作为参数,字段或局部变量的类型; 有时作为返回类型(虽然更好的编程实践更具体)。 通配符从不用作泛型方法调用,泛型类实例创建或超类型的类型参数。 另一方面,在factory方法中, T是将由编译器推断的类型参数,并且由于Li ...
  • 在VS2010(IIRC)中更改了类型推断 - 基本上编译器的功能稍微强一些。 这不是.NET本身的变化问题。 两个简单的选择: 改为使用lambda表达式: .Select(x => GetSiteQueryForXMLElement(x)) 使用方法组转换指定类型参数: .Select(GetSiteQueryForXMLElement); 要么应该工作正常。 Type inference changed in VS2010 (IIRC) - basical ...

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。