PHP threading call to a php function asynchronously

http://php.net/pthreads http://docs.php.net/Thread PHP certainly can support threading. Loading data from a SQL/NoSQL database in parallel is definitely a possibility. See the PHP manual, examples found in github and pecl packages, and a little bit more info on http://pthreads.org Please note, the documentation did state that this is part of the core, this is ( my … Read more

Does PHP time() return a GMT/UTC Timestamp?

time returns a UNIX timestamp, which is timezone independent. Since a UNIX timestamp denotes the seconds since 1970 UTC you could say it’s UTC, but it really has no timezone. To be really clear, a UNIX timestamp is the same value all over the world at any given time. At the time of writing it’s … Read more

PDO with INSERT INTO through prepared statements [closed]

You should be using it like so <?php $dbhost=”localhost”; $dbname=”pdo”; $dbusername=”root”; $dbpassword = ‘845625’; $link = new PDO(“mysql:host=$dbhost;dbname=$dbname”, $dbusername, $dbpassword); $statement = $link->prepare(‘INSERT INTO testtable (name, lastname, age) VALUES (:fname, :sname, :age)’); $statement->execute([ ‘fname’ => ‘Bob’, ‘sname’ => ‘Desaunois’, ‘age’ => ’18’, ]); Prepared statements are used to sanitize your input, and to do that … Read more

How to use basic authorization in PHP curl

Try the following code : $username=”ABC”; $password=’XYZ’; $URL='<URL>’; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$URL); curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_USERPWD, “$username:$password”); $result=curl_exec ($ch); $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code curl_close ($ch);

How to parse JSON and access results

If your $result variable is a string json like, you must use json_decode function to parse it as an object or array: $result=”{“Cancelled”:false,”MessageID”:”402f481b-c420-481f-b129-7b2d8ce7cf0a”,”Queued”:false,”SMSError”:2,”SMSIncomingMessages”:null,”Sent”:false,”SentDateTime”:”\/Date(-62135578800000-0500)\/”}”; $json = json_decode($result, true); print_r($json); OUTPUT Array ( [Cancelled] => [MessageID] => 402f481b-c420-481f-b129-7b2d8ce7cf0a [Queued] => [SMSError] => 2 [SMSIncomingMessages] => [Sent] => [SentDateTime] => /Date(-62135578800000-0500)/ ) Now you can work with $json … Read more

PHP Session data not being saved

Thanks for all the helpful info. It turns out that my host changed servers and started using a different session save path other than /var/php_sessions which didn’t exist anymore. A solution would have been to declare ini_set(‘ session.save_path’,’SOME WRITABLE PATH’); in all my script files but that would have been a pain. I talked with … Read more