Jump to content

[SOLVED] PHP - Windows CLI


kevinkorb

Recommended Posts

I have PHP 5.2.3 running on Windows Server 2K3.

 

Everything works fine through apache, however I'm creating some automated tasks and wanted to us Windows Task Scheduler to run them through the command line.

 

Test 1: - Send simple email:

 

<code>

<?php

mail("[email protected]", "test email sub1", "test body", "From: [email protected]");

?>

</code>

 

Now I tried running that three different ways.

 

(I have a copy of the php.ini in the same folder as the script I'm running)

 

I tried:

php test.php

php -n test.php

php-win test.php

 

The only one that completed and sent the email was php -n test.php.

 

Then I ran a simple test to try to connect to my database.

 

After trying to run it every way I thought I could, the error message came back that it couldn't instantiate the mysqli class.

 

So I imagine it is a php.ini problem, however I'm not able to resolve it in any way.  Any ideas?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/66524-solved-php-windows-cli/
Share on other sites

That does work, however I'm looking for a 'best practices' solution.  The box is going to be working very hard to begin with (The mysql database is at about 25 million rows in 130 tables) the budget is decent for the project, I would really not want to resort to ie for automated tasks.

 

You solution would work, however I'm looking for a bit more.

 

Thank you.

I can create a simple .bat file containing...

 

php d:\www\vhosts\mydomain.com\myfiletoautomate.php

 

and then Schedule that through the task scheduler.

 

That part is easy, its just getting php to play nicely in the command line format that is the problem.

I figured it out.

 

I copied my php.ini file to the same folder and then gutted the extensions except for mysqli (which I will defiantly need).

 

Then to call the php script I used:

 

php -c php.ini test.php

 

It worked.

 

I'm chalking it up to an extension(s) that isn't compatible with the php cli for windows.

 

Way too much fun for what I wanted to do.

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.