• Home
  • About
  • Who Am I?
  •  

    Web based FTP Sync Tool written in PHP

    December 4th, 2007

    FTP Sync Jobs ScreenFTP Sync 0.9

    PURPOSE:
    To upload files which have changed to your production server , automating the task of comparing which files have changed. You simply create a FTP job
    in the script , run the job and it will upload the changed files for you.

    REQUIREMENTS:
    FTP functions are required for this script to work.
    PHP 4 Or 5
    MySQL 4+

    INSTALL:
    Open dbinc.php and put in the database connection variables in there. Once done run installer.php from your browser and you are all set to go.
    Its advised to remove installer.php once you have finished installation.

    SECURITY:
    It if advised that the admin creates users and allocates jobs to them. Also the admin should block access to the database and script files
    from general staff.

    INFO:
    We made this script for our internal use , thought it might be useful for some of you out there. It was a tiring job to find which files needed to be uploaded
    to the main server after development on local server. Thus i created this script , where you can create jobs and upload folders and files which were changed.

    The decision to upload happens on 3 rules:

    1 : you can provide time and date in the job page , files which were created after that time will be uploaded.

    2 : you can ask the script to match the time against the server file , the script would calculate the time offset and calculate if the file has
    changed since last upload.

    3 : The script also keeps a log , if the file changed after last upload , it will upload the file.

    You can exclude the files you dont want to upload, for instance you wont want to upload and overwrite config.php or something like that. So you
    can create the skip list. The skip list is the path of the file from the source directory you have provided.

    For instance if you have a source directory called “/www/something/upload/” , and you dont want to upload the file “/www/something/upload/config.php”
    or the folder “/www/something/upload/users/images” then you would put in something like this:

    config.php
    users/images

    Remember no trailing slash for folders.

    You need to have writable permissions for the logs folder , also if you want to utlize the copy permissions feature you will need the BcMath library
    compiled with PHP.

    The admin can run any job , but if you want to have users which can run specific jobs only please utilize the users section , in which a user can
    run all jobs or only specific jobs.

    Same goes for the jobs , you can set an attribute to allow all users to run the job.

    This code has been tested on PHP 5 and PHP 4.4.

    You are free to modify the code as you please. The code is released in the public domain under the GPL license.

    Enjoy!



    Affordable PHP 5 and MySQL 5 Hosting Available

    August 25th, 2007

    Decode IT has announced PHP 5 and MySQL 5 hosting.  After signup customers will be given a choice between version 4 and 5. The servers are dual core servers with high uptime and reliability. Small packages are ideal for Wordpress installations which can be done with clicks via the Fantastico control panel. All accounts contain the all time great CPanel account manager.

    Here is the overview….
    50 MB Hosting - $2.00 pm
    100 MB Hosting - $4.00 pm
    200 MB Hosting - $8.00 pm
    500 MB Hosting - $20.00 pm
    1000 MB Hosting - $35.00 pm

    You can find the details of the packages here.

    Enjoy!!



    Practical Tips on Reducing Load of MySQL Queries

    February 13th, 2007

    Alot of PHP/MySQL programmers out there , specially the ones just starting out make some mistakes while using queries. The ideas i am going to outline aren’t just limited to MySQL , they can be equally applied elsewhere as well. We need to keep in mind the fact that MySQL will use more RAM and CPU than it should if inefficient queries are written.

    • For instance one common mistake is to use “SELECT * from table1” , unless you don’t need to use all of the fields i strongly suggest against it. Use something like “SELECT field1,field2 from table1
    • Make sure you know what you are doing when using JOINs. Use “explain” to see how many rows are actually being scanned for the query to execute and bring the result. A lot of times its better to break the query up into several queries. JOINS ARE HEAVY!
    • I have seen people use order by clause in queries where they need to get just the count of the records. That’s totally unintelligent. Order by clause uses up RAM as well to sort the data. Avoid it where it can be avoided.
    • Saving images in DB is probably not a really good idea after all. Atleast I think so. If you can , doesn’t mean you should.
    • Integer primary keys are faster than making username the primary key or something similar.
    • Fixed length fields are processed faster than variable length fields.
    • Use indexing wisely. Indexing helps in query the database faster BUT insertion and updates are slower.
    • Sometimes it better not to create text book database structure aka normalization , sometimes a little redundancy can help minimize number of queries AND/OR load on database, specially when dealing with large databases.
    • Keep in mind that in the loop while($array=mysql_fetch_array($queryresult)) , the transaction will keep the query open until the end of the loop. So if there is some heavy processing happening inside the loop on the result data, it is probably a good idea to first run the query loop and store the data you want to process in arrays and then later on process on the array. I find this technique helpful on many occasions.
    • Using mysql_pconnect doesnt always help .
    • Using mysql_free_result is probably a good idea.
    • mysql_insert_id is a useful function to get newest primary key of the record , rather than using “….order by id desc limit 1″
    • If you know you will be using some mysql field data alot , like the username of the logged in user , its always a good idea to store it in session , rather than banging on mysqls door again and again for it.
    • ENUM field type is very useful , just like fixed length fields. Data processing on ENUM fields is quite fast.
    • Using count(*) in queries instead of mysql_num_rows is faster i believe.
    • I believe if you are storing signup dates etc , its probably a good idea to have the field as integer instead of datetime and put in mktime() value. This only applies to current and future dates. In cases where past dates are possible datetime should be used. As you never know if that date can be earlier than 1970. Storing mktime gives you faster processing and manipulation of data is easier as well in PHP with the date() function.
    • Dont use fulltext unless you really have to.
    • And finally DO USE PRIMARY KEYS , dont be affraid to use them , they can help you down the road. For instance “DELETE from table1 WHERE id = 1″ and “DELETE from table1 where firstname=’php’ and lastname=’rox’” , the first query i reckon will run faster.

    Those are all i can think of right now. Please remember i am not an expert on MySQL , the above are based on professional experience with PHP and MySQL. Another thing to remember here is , all of these points might seem insignificantly small but when piled up together. They can cause major havoc. Specially when large databases are question.

    Hope the tips can really help someone.