Link to home
Start Free TrialLog in
Avatar of Scott Fell
Scott FellFlag for United States of America

asked on

PHP bulk inserting records into multiple tables from a scheduled task/cron job

I have a pure php page that is set up to run about  a 100 transactions where I am adding and updating to several tables and making a call to a payment processor.  Everything is working nicely.

I have done this many times on the asp/vb side.  What do I need to do in order to make sure the page does not time out.  Just the set time limit?  http://php.net/manual/en/function.set-time-limit.php. I  would prefer to make this change in the scripting than an ini setting.

This is something that is going to be scheduled to run every night so I don't really expect any more than 100 transactions and it will probably be a lot less and I don't have to worry about this. But if I want to make sure I could run more.  Any tips and gotchas to know.

This is on windows and my plan is to have scheduled task hit a vbs script that will post to the php page.   Would it be best to just use CLI?  Instead of hitting the vbs, just run http://php.net/manual/en/install.windows.commandline.php C:\PHP5\php.exe -f "C:\PHP Scripts\script.php" -- -arg1 -arg2 -arg3
ASKER CERTIFIED SOLUTION
Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Dave Baldwin,
Command line PHP does have a timeout.  It's just default to 0.  It's specified in the link you provided.
When running PHP from the command line the default setting is 0.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scott Fell

ASKER

Ray, are you flushing the output?
That's a whole different question with a lot of moving parts.  You probably can't go wrong with flush() in the script, but there are a lot of ways that PHP, initialization settings, your server and the client's browser can interact to frustrate your efforts.  Some of this is described on the flush() man page.
For some reason, I couldn't use  the format suggested and it must have something to do with plesk.  I tried many variations and nothing worked.   It's even outlined in the plesk KB.  http://kb.sp.parallels.com/en/115292.  My web host support suggested to use the powershell version and that's what I did.

Path to executable file: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    Arguments: -c "(new-object system.net.webclient).downloadstring('http://domain.test/folder/page.php')"

Open in new window