Asterisk PHP

Please note: this library has significant threading problems. It is not recommended for production use.


Asterisk PHP allows you to control the dial-plan and write applications for Asterisk in PHP. This is faster and more flexible than phpAGI.



Asterisk PHP is known to work with Asterisk 1.0.6 to 1.0.9 and PHP 4.3 and 5 with zts enabled. Other versions may work.


A. Build and Install Asterisk as normal.
B. Build PHP with Asterisk support
	1. Copy source to sapi folder
		cp -R asterisk_php <path_to_php_source>/sapi/asterisk
	2. Rebuild PHP conf system.
		cd <path_to_php_source>
		buildconf --force
	3. Configure Asterisk into PHP.  A separate php installation is recommended.
		./configure <normal options> --with-asterisk=<path_to_asterisk> --prefix=/usr/local/php5 --enable-maintainer-zts
		./configure <normal options> --with-asterisk=<path_to_asterisk> --prefix=/usr/local/php4 --enable-experimental-zts
		NOTE: do not compile PHP with any other SAPI (example apache).
	4. Build PHP
	5. Install PHP
		make install
	7. Make sure the php library is configured in /etc/ld.so.conf.  Run ldconfig after editing /etc/ld.so.conf.
C. Configure Asterisk with PHP support.
	1. Add load => res_features.so to modules.conf
D. Test it.
	1. From the CLI: show application PHP
	2. Create /tmp/test.php (see test.php)
	3. Add to an extension:
		exten => 1234,1,PHP(/tmp/test.php|hello|world);
	4. Dial 1234
	5. Look at /tmp/test.php.out
E. Use it and report problems or feature requests.

Function Reference

int asterisk_answer([string channel])
int asterisk_best_codec([string channel])
int asterisk_bridge_call([string channel,] string peer[, array options])
array asterisk_chanlist(void)
int asterisk_channel_make_compatible([string channel,] string peer)
int asterisk_channel_setoption([string channel,] int option, string data)
int asterisk_channel_status([string channel])
int asterisk_cli(int fd, string cmd)
string asterisk_codec2str(int codec)
int asterisk_control_streamfile([string channel,] string file, string fwd, string rev, string stop, string pause[, int skipms])
int asterisk_db_del(string family, string keys)
int asterisk_db_deltree(string family[, string keytree])
int asterisk_db_get(string family, string keys)
int asterisk_db_put(string family, string keys, string value)
int asterisk_exec([string channel,] string app[, string data])
string asterisk_getdata([string channel,] string filename[, int maxdigits[, int timeout]])
int asterisk_getformatbyname(string name)
string asterisk_getformatname(int format)
int asterisk_get_priority([string channel])
string asterisk_get_variable([string channel,] string variable)
array asterisk_get_variables([string channel])
int asterisk_hangup([[string channel,] int cause])
asterisk_log(long log, string message)
int asterisk_manager_command(int fd, string cmd)
asterisk_moh_start([[string channel,] string class])
asterisk_moh_stop([string channel])
int asterisk_recvchar([[string channel,] int timeout])
string asterisk_request(string type, int format, string data, int &cause)
string asterisk_request_and_dial(string type, int format, string data, int timeoute, int outstate, string callerid)
int asterisk_say_character_str([string channel,] string chars, [string ints[, string lang]])
int asterisk_say_date([string channel,] [int time[, string ints[, string lang[, string format[, string timezone]]]]])
int asterisk_say_datetime([string channel,] [int time[, string ints[, string lang]]])
int asterisk_say_datetime_from_now([string channel,] [int time[, string ints[, string lang]]])
int asterisk_say_digit_str([string channel,] string digits, [string ints[, string lang="en"]])
int asterisk_say_number([string channel], int number, [string ints[, string lang[, string options]]])
int asterisk_say_phonetic_str([string channel,] string text[, string ints[, string lang]])
int asterisk_say_time([string channel,] [int time[, string ints[, string lang]]])
int asterisk_senddigit([string channel,] string digit)
int asterisk_send_image([string channel,] string image)
int asterisk_sendtext([string channel,] string text)
asterisk_set_best_read_format([string channel])
asterisk_set_best_write_format([string channel])
asterisk_set_callerid([string channel,] string callerid[, boolean anitoo])
int asterisk_set_context([string channel,] string context)
int asterisk_set_extension([string channel,] string exten)
int asterisk_set_priority([string channel,] int priority)
asterisk_set_read_format([string channel,] int format)
int asterisk_set_variable([string channel,] string variable, string value)
int asterisk_setwhentohangup([[string channel,] int timeout])
asterisk_set_write_format([string channel,] int format)
string asterisk_state2str(int state)
int asterisk_stream_file([string channel,] string filename[, string digits[, int offset[, string lang]]])
int asterisk_tdd_mode([[string channel,] int mode])
asterisk_verbose(int level, string message)
asterisk_waitfor([string channel,] int wait)
int asterisk_waitfordigit([[string channel,] int timeout])


none at the moment.

Contact me

If you want to send actual e-mail, think about this: My name is david and my domain is eder.us.

Send me some bitcoins: 1PAc2UFS77zhsfdLz86rHynREXTKjWrRzY