How to Create a PHP Function
A php function is a block of code that can be called and executed from anywhere in your application, thereby eliminating the need to repeatedly re-write the same logic. There are a number of built-in functions that ship with the PHP runtime, and developers can also create their own custom functions for specific needs.
When creating a function, it is important to use the right keywords in the function definition. The keyword function is followed by a name, which must be a valid integer, and the arguments are specified in parenthesis. Arguments must be separated by commas and should be typed correctly as well. It is also worth mentioning that PHP supports function returns as well. The function return statement adds a return value to the end of the function definition, and when used, the function will return that value if the call succeeds.
One other thing to note about the example above is that the second parameter of the function is set to be a constant. This is a good practice for creating functions as it ensures that the function will always return the same value.
In the example above, we are using a sftp class to perform SFTP file transfers. The sftp class leverages libssh2 which allows you to upload large files very quickly. Libssh2 will send your chunk of data in multiple packets of 32K each, allowing the transfer to be very fast. In order to use the sftp class, you must have an ssh2 server installed and configured for it to support the SFTP protocol.