Jump to content

Background Process


Asheeown

Recommended Posts

Okay, primary goal here is this:

User views a page that executes a background php script that continuously pulls data from a certain source and loads it into the database.

 

Two things I am having problems with

1. The script won't execute I am doing a simple script output to a text file and it doesn't show but works in command prompt

2. I cannot seem to figure out how to get the PID of the php process running.

 

Installation structure is xampp full installation so phhp is under the xampp folder, this is not the structure for my real server, is is a server 2008 server with fastcgi php installed.

 

Here is the code I am using to execute the file

 

<?php
$Command = exec("C:\xampp\php\php.exe C:\xampp\php\myscript.php > output.txt");
echo $Command;
?>

Link to comment
https://forums.phpfreaks.com/topic/122154-background-process/
Share on other sites

This is why we use cron and don't even fathom using Windows, Fearsoldier. >_<  If you want it to not hang, you need to redirect output to another file, which I don't think Windows on CMD can do with the > like Linux can.  And on Linux, if you needed the data afterwards, you could always use a named pipe. =P  Good luck getting this to run on Windows.  I'd check on how to redirect output on CMD.

Link to comment
https://forums.phpfreaks.com/topic/122154-background-process/#findComment-633223
Share on other sites

Yes

It works for command prompt using the EXACT same execution as I use in the PHP.  Php has to have a way to not want any output or maybe an alternative way would do?  This is a user triggered script so when a user browses to this page it's going to start, I can't have it hung up in the background.

Link to comment
https://forums.phpfreaks.com/topic/122154-background-process/#findComment-633233
Share on other sites

Well before I sign off tonight I figure I should post my new code, this code is working, but isn't working lol.

 

<?php
$dir = "C:/xampp/php";
$php_path = "C:/xampp/php/php.exe";
$file = "myscript.php";
$cmd_options = "-t " . time();
$wscript = new COM('WScript.Shell');
echo $wscript->Run("cmd /K CD $php_path $dir/$file > output.txt  &  ", 0, false);
?>

 

Replicated it completely in Windows and I get an Access is Denied read out.  Vista kills me but Windows Server 2008 does the same access bull**** so does anyone know how to setup permissions so that it won't require admin access?  Or any other hints perhaps?

Link to comment
https://forums.phpfreaks.com/topic/122154-background-process/#findComment-633303
Share on other sites

Success!  I got it working, OK one more question, the com_get to pull a property from a COM object has been deprecated in PHP5.  I need to pull the process ID from the execution I am running.

 

 

$dir = "C:/xampp/php";
$php_path = "C:/xampp/php/php.exe";
$file = "myscript.php";
$cmd_options = "-t " . time();
$wscript = new COM('WScript.Shell');
$Command = $wscript->Run("$php_path $dir/$file", 0, false);

Link to comment
https://forums.phpfreaks.com/topic/122154-background-process/#findComment-633776
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.