Jump to content

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"?

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

I seem to have it working, but now I receive "Call to undefined function mysql_connect()", but this is only when the script is called from the batch file. If i call the script form the browser it works fine.

1. Why on earth are you calling a batch file just to run another PHP script?

2. Why are you using php-cgi?

3. argv is available to PHP scripts run on the command line (cli).  See #2

Edited by AbraCadaver

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?

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).

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.

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.