PHP's tag archives

Linux系统下PHP发送邮件失败的解决办法

是否安装Sendmail 检查下php.ini设置是否正确 cat /etc/php.ini | grep sendmail_path 正确的结果应该类似这样 sendmail_path = sendmail -t -i 检查下sendmail是否安装 which sendmail 正常的结果应该类似这样 /usr/sbin/sendmail 如果上面的路径没有找到sendmail 检查下是否安装了包 yum list installed | grep sendmail 这时的情况又分为二种: 如果安装了这个包,就给卸载了重新装一遍。 如果没装,直接装上。 sendmail---stat=Service unavailable 今天尝试着想要在linux终端上直接用mail命令(e.g: echo "hello" | mail -s "hello test" xxx@139.com)给我139.com的邮箱发邮件时,139.com邮箱根本收不到,但是总是可以在/var/mail/root下面找到我刚才发的邮件,其实这是因为发送失败了,从而被sen...

Backup mysql database with php and zip

Many php applications prefer to backup the mysql database from within the application and save it as an archive. The mysqldump commandline utility can be used to perform this function of backing up a mysql database as sql file. The command would be like this : The above command shall dump the database named $db_name into a sql file in directory $dir. This sql file shall be next zipped using php's Ziparchive class. In the above example backups/backup.sql is the path to the sql fil...

MySQL Optimize Top 21 Tips

1. Optimize Your Queries For the Query Cache Most MySQL servers have query caching enabled. It’s one of the most effective methods of improving performance, that is quietly handled by the database engine. When the same query is executed multiple times, the result is fetched from the cache, which is quite fast. The main problem is, it is so easy and hidden from the programmer, most of us tend to ignore it. Some things we do can actually prevent the query cache from performing its task. vie...

HowTo install ImageMagick PHP extension

How to install ImageMagick from YUM repository The easiest way to install ImageMagick extension is to install it from yum repository: 1) Run “yum search imagick” command to check if ImageMagick extension is available in your repositories. If you get the line below – ImageMagick extension is available in your repository and you can install it using “yum install” command 2) Run “yum install php-pecl-imagick” to install ImageMagick extension. 3) Restart Apache webserver. How...

Import CSV File into PHP Array

A Comma-separated values (CSV) file stores tabular data (numbers and text) in plain-text form. Often it is one record per line seperated by a comma or any other delimeter. The comma , is often used in USA/UK CSV files where Germany often uses a ; instead This is an example of a simple CSV file that has 4 fields and 2 records (1 per line) In PHP it is often useful to be able to read a CSV file and access it’s data. That is where the fgetcsv() funtction comes in handy, it will re...

Capture Image Screenshots with PHP

Since PHP 5.2.2 it is now possible to capture a website or any window’s screenshot to an image with PHP as long as it is running on a Window’s machine. Most web-servers are running Linux but this could be useful for a tool on your home Dev server. Capture Whole Screen Capture an Application’s Window

PHP Operator ===

PHP’s === Operator enables you to compare or test variables for both equality and type. Refer below for example.

Create a REST API with PHP

One of the latest (sort of) crazes sweeping the net is APIs, more specifically those that leverage REST. It’s really no surprise either, as consuming REST APIs is so incredibly easy… in any language. It’s also incredibly easy to create them as you essentially use nothing more than an HTTP spec that has existed for ages. One of the few things that I give Rails credit for is its well thought-out REST support, both for providing and consuming these APIs (as its been explained by all the R...

Create web server on Mac

Apache Start Apache Check it's working: http://localhost/ PHP In /etc/apache2/httpd.conf, uncomment this line: Restart Apache Fix a warning appearing in phpinfo() Create /etc/php.ini and make it writable In php.ini, find this line: Uncomment it and insert your time zone (http://php.net/manual/en/timezones.php) Restart Apache MySQL Download the MySQL package for Mac OS X.5 (32 or 64 bits depending on your machine) Install everything in...

ExtJS4 : read posting JSON data in PHP

I am working on a Ext-JS web application which needs to send data to the PHP server side to store. It took me a while to find out how to decodes the receiving JSON string in PHP. Ext-JS Assume you have a model and calling save to send a ajax request. PHP If you use $_POST variable to pass the JSON string, you won’t see anything. It is just an empty array. This is because the Content-Type in the Request packet is different now, application/json. The JSON expression string in the...