Some functions (fgetcsv, fputcsv for example) require a stream handle to work with. Similarly you have methods within zend_pdf to expect to read and write image data from a stream.
This can be inconvenient at times when you already have the data sitting in a variable. A way of getting around the need to worry about physically creating a file is to use the memory stream type.
PHP supports a number of input / output streams ranging from the usual stdin, stderr, stdout to memory, temp and filter.
See http://php.net/manual/en/wrappers.php.php for more information on these.
But looking at the memory type, it's very easy to use. Simply $fh = fopen('php://memory', 'wb+'); and you can use the usual file functions you would typically associate with an ondisk file.
You can fread, fwrite, file_get_contents on the memory stream or push it out over the network using the tcp streams PHP offers. PHP streams are a powerful and often underutilised aspect of the language.
A flawed but interesting set of automated benchmarks of various programming languages against one-another.
A quick tip this one. Whenever you want to group a reporting query by date (by month, day, year) you can use the following approach in MySQL
SELECT DATE_FORMAT(yourdate, '%Y-%m') AS grouping_date COUNT(id) FROM yourtable GROUP BY grouping_date;
Change the date format to whatever date quantum you want to report on, i.e. just have '%Y' for a yearly grouping, or have '%y-%m-%d' for a daily one.
If for some reason a Worldpay Business Gateway callback fails, it can often be difficult to manually complete an order.
The quickest way, is actually very simple, and that is to simply use curl to resubmit the callback. This is assuming you have found, and if necessary corrected, the issue that stopped the callback succeeding in the first place.
When a callback fails, either through a time out or some internal (500) error, you will receive an email from Worldpay notifying you. This mail includes two attachments one the request data Worldpay sent to your callback URL including the encoded post data as well as the response from your server.
Now assuming you work around your security arrangements (e.g your callback URL should listen only to certain addresses and expect auth credentials), you can use curl to resubmit your post data:
curl -d ‘testMode=0&authCost=716.86¤cy=GBP&address=15+Somewhere+Street&countryString=United+Kingdom&callbackPW=xyz&installation=2555555&fax=&countryMatch=Y&transId=1000000000&AVS=2222&amountString=%26%23163%3B716.86&postcode=XX11+1XX&msgType=authResult&name=Mr+Test+Tester&tel=0208+111111&transStatus=Y&desc=Test+Transaction+1234&cardType=Visa+Delta&lang=en&transTime=1277741069650&authAmountString=%26%23163%3B716.86&authAmount=716.86&ipAddress=80.80.80.80&cost=716.86&charenc=UTF-8&instId=2555555&amount=716.86&compName=Testing Tester&_SP.charEnc=UTF-8&country=GB&rawAuthMessage=cardbe.msg.authorised&authCurrency=GBP&[email protected]&cartId=12345678&rawAuthCode=A&authMode=A’ \
'https://mysite.com/callback'
Now your program can handle the completion of the order as normal.
You can make this more sophisticated, by having a mail reader retrieve any missed payment notifications and parse them. With each failure notification you can add a retry to a job queue, or other batch processing stack. It would be worth adding some sort of retry threshold though, as well as sending notifications to developers to ensure there is no serious malfunction occurring.
Really handy tip this one, via the mactricksandtips.com website. See here: http://www.mactricksandtips.com/2010/06/converting-files-in-terminal-including-docx.html
For the impatient, the cli programme that weaves this magic is called 'textutil'.