我制作了这个脚本来测试PHP的执行作为后台进程
foreach($tests as $test) {
exec("php test.php ".$test["id"]);
}
Run Code Online (Sandbox Code Playgroud)
正如php过程背景中提出的 以及如何使用PHP通过Google Calendar API添加大量事件通知提醒?和php执行后台进程
但是,如果没有添加test.php,脚本的运行速度就会超过一个脚本.
我究竟做错了什么?
提前致谢!
我想在某些情况下在后台运行以下代码:
文件A:
// ------------------- Some Code Before Following -----------------------
// send notification to given device token
$notification = new Notification();
$notification->sendNotification($token,$count);
// ------------------- Some Code After Above ------------------------
Run Code Online (Sandbox Code Playgroud)
这将称为以下类:
// Here I am sending notification to given device token (APNS Push Notification)
<?php
class Notification
{
public function sendNotification($token,$count)
{
if(strlen($token)%16 == 0)
{
// set Device token
$deviceToken = $token;
$passphrase = 'xxxxx';
$badge = $count;
// Displays alert message here:
$message = 'Hello! There.';
$ctx = stream_context_create();
stream_context_set_option($ctx, …Run Code Online (Sandbox Code Playgroud) php notifications background-process apple-push-notifications
方案是:当用户上传图像时,我们在服务器上进行图像大小调整,但是我没有等待完成这项工作,而是希望它立即响应用户.如果有一个可用的线程,我会正确地使用线程来完成这个任务,但据我所知,php中没有线程,所以我怎样才能实现这个目标呢?感谢您的想法和建议.
举例说明: f.php :
d$=$_Get['ad'];
print d$;
Run Code Online (Sandbox Code Playgroud)
索引.php :
for $i=0 to 200000
// run f.php?ad=i$
Run Code Online (Sandbox Code Playgroud)
运行 f.php 但不要等待完成 f.php 怎么办?
我找到了php asyncronus但我现在不知道这是真的有效还是现有的其他解决方案,或者这是最好的解决方案?!
何时使用 exec 以及如何使用?
我有一个PHP脚本,其中我编写了以下代码
$client = new \Predis\Client();
$client->select(4);
$client->lpush('emailid',$x['to']);
$command = "/usr/bin/php5 -f /var/www/Symfony/src/Ens/NewBundle/Controller/cron.php";
exec( "$command > /dev/null &", $arrOutput );
return $this->render('EnsNewBundle:Email:header.html.twig');
Run Code Online (Sandbox Code Playgroud)
在这里我写了另一个名为的PHP脚本cron.php.我想在后台运行该脚本.我想检查这是否在后台运行.我该怎么检查呢
例如,我有以下脚本。
在这种情况下,我想获得 X1 和 Y1 的值,但 exit() 不允许我这样做
请提前感谢并特别感谢 Mark Setchell :P(如果他看到这个)
$im = imagecreatefromjpeg("omr.jpg");
for($x=0;$x<100;$x++) {
for($y=0;$y<100;$y++)
{
$rgb = imagecolorat($im,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if($r<128 && $g<128 && $b<128){
printf("%d,%d: %d,%d,%d\n",$x,$y,$r,$g,$b);
exit;
}
}
}
for($x1=1170;$x1<1270;$x1++){
for($y1=0;$y1<100;$y1++){
$rgb = imagecolorat($im,$x1,$y1);
$r1 = ($rgb >> 16) & 0xFF;
$g1 = ($rgb >> 8) & 0xFF;
$b1 = $rgb & 0xFF;
if($r1<128 && $g1<128 …Run Code Online (Sandbox Code Playgroud)