Jump to content

Call bat file from PHP that executes a php script with parameters


spertuit

Recommended Posts

From a web page I need to call a .bat file and have that execute a php script. I need to pass a parameter from php to other php file.

 

So it looks like my first php script would be something like this:

system("cmd /c C:test.bat");

My bat file would be something like this:

@echo OFF
"C:\Program Files (x86)\PHP\v5.4\php-cgi.exe" C:\test.php%*

But how can I pass a parameter, like I would call "file.php?event=3"?

Link to comment
Share on other sites

So right now I'm trying

 

In my first php script:

<?php
$par= "3";
$test=`c:\test.bat $par`;
echo "<pre>$test</pre>";
?>

Than my test.bat:

@echo OFF
"C:\Program Files (x86)\PHP\v5.4\php-cgi.exe" C:\inetpub\wwwroot\Lafourche\parish
Test.php?event=%1
Link to comment
Share on other sites

Lot of good questions, this seem liked the best way.

 

i have a web portal where companies can log in and enter their employees.

There is a process where the employees are created a placard and the placards are than zipped and emailed to the company admin

The problem I have is the script that mails the zipped placards to the company admin takes too long to run.(Its over 1,000 admins) The browser gets half done and than a 500 error

I thought the best way around this is to create a batch script that runs in the background and maybe it can execute my mail script.

 

Any suggestions?

Link to comment
Share on other sites

I thought the best way around this is to create a batch script that runs in the background and maybe it can execute my mail script.

exec'ing a batch file like you are will not run the process in the background. PHP will wait for that program to finish executing before it continues with your script. As for ways around a time consuming process, there are various options, such as:

 

1) Store the info into the database, and then have a scheduled task periodically run a PHP script which checks the database

2) If you use exec, you need to use a program that will really let you run it in the background, such as hstart

3) Create some sort of batching system w/ ajax that will run the task in batchs and provide a status update to the user (they would still have to wait for it to finish though).

Link to comment
Share on other sites

exec'ing a batch file like you are will not run the process in the background. PHP will wait for that program to finish executing before it continues with your script. As for ways around a time consuming process, there are various options, such as:

 

1) Store the info into the database, and then have a scheduled task periodically run a PHP script which checks the database

2) If you use exec, you need to use a program that will really let you run it in the background, such as hstart

3) Create some sort of batching system w/ ajax that will run the task in batchs and provide a status update to the user (they would still have to wait for it to finish though).

 

Creating a batching system w/ajax, good suggestion. I think the user can wait for awhile and at least they will get immediate results if the process completes. Ill see what I can come up with.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.