Joshua's Thoughts

How to Pass Arguments to PHP in Command Line

Tags: , , , , ,

I did a little bit of searching this morning for how to pass arguments to php via command line because I was working on setting up a php script to run on a cron in Windows (using WAMP).

It’s actually pretty easy. Say your command line looks like this:

>path-to-php/php.exe path-to-script/script.php

Passing an argument to the php script would look like this:

>path-to-php/php.exe path-to-script/script.php arg1 arg2

PHP will read the arguments using the $argv variable. So in our example, $argv[0] would be the name of the script (script.php), $argv[1] would be arg1 and $argv2[2] would be arg2.

Another example:
>path-to-php/php.exe path-to-script/script.php 15

Say you just wanted to echo out the argument contents:

echo $argv[1];

Pretty cool. Here’s the forum post where I discovered this information.

how to enable libcurl in wamp

Tags: , , ,

if you’re getting “Fatal error: Call to undefined function: curl_init()” and you’re using wamp, you’ve got to perform a few extra steps to get curl working.

wamp comes with a crap load of extensions, including curl. it’s just a matter of getting the extension loaded when wamp is started. and no, enabling php_curl from within the wamp menu is not how to do it. for some reason, that just doesn’t work.

here’s what you need to do:

  • open C:\wamp\bin\php\php5.2.6\php.ini
  • find “;extension=php_curl.dll” and remove the semicolon to uncomment the line
  • do the same for C:\wamp\bin\apache\apache2.2.8\bin\php.ini

it doesn’t matter what version of wamp you’re running at the time, the process is the same.

next, you need to make sure apache can find the extension to load, so make sure that in both php.ini files, you find the lines:

; Directory in which the loadable extensions (modules) reside.
extension_dir = “C:\wamp\bin\php\php5.2.6\ext”

… and have them both point to the ext folder within your PHP folder. by default, they will be something like /usr/bin/ext. change that.

restart wamp and it should all work. you can look in the phpinfo to see if curl was loaded. if it still doesn’t work, check the apache error log within the wamp logs folder.

write your own im bot in 5 minutes

Tags: ,

this site shows how easy it is to use imified.com to create a bot that will automatically interact with whoever is messaging your bot.

php api wrapper for quickbase

Tags: , ,

For anyone interested in using PHP with QuickBase, here is a PHP wrapper. It uses cURL to post XML and HTTP POSTS to QuickBase. Big thanks to Alex Wilson for providing most of the original code base. The documentation for the QuickBase API can be found here.

Read on…