Skip to content

Instantly share code, notes, and snippets.

View missoxd's full-sized avatar

Misso Marchewsky missoxd

View GitHub Profile
<?php
/*
\Error implements \Throwable
\Exception implements \Throwable
catch (\Error $e) - Will only catch \Error exceptions and children
catch (\Exception $e) - Will only catch \Exception exceptions and children
catch (\Throwable $e) - Will catch all
- - - - - - - - - -
<?php
// Define the default socket timeout
ini_set('default_socket_timeout', 360);
// Start Socket Server
$errno = 0;
$errstr = '';
$socket = stream_socket_server('tcp://0.0.0.0:8000', $errno, $errstr);
<?php
class Container
{
private array $instances = [];
public function set(string $key, $value): void
{
if (is_string($value) || is_callable($value)) {
$value = $this->resolve($value);
@missoxd
missoxd / php-guzzle-curl-promise-test.php
Last active September 7, 2020 20:01
Testing Guzzle cURL Mult Handler with Promises
<?php
/**
* We are using Guzzle v6.
* composer require "guzzlehttp/guzzle=~6.0"
*/
//Load composer.
require __DIR__ . '/vendor/autoload.php';
//Use statements.
@missoxd
missoxd / magento2-deferred-async-webrequests.php
Created September 4, 2020 23:26
Magento 2 deferred async web requests test
<?php
require __DIR__ . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$objectManager->get('\Magento\Framework\App\State')->setAreaCode('adminhtml');
$registry = $objectManager->get('\Magento\Framework\Registry');
$registry->register('isSecureArea', 'true');
wget -O /tmp/YaHei.Consolas.1.12.zip https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/uigroupcode/YaHei.Consolas.1.12.zip
unzip /tmp/YaHei.Consolas.1.12.zip
sudo mkdir -p /usr/share/fonts/consolas
sudo mv YaHei.Consolas.1.12.ttf /usr/share/fonts/consolas/
sudo chmod 644 /usr/share/fonts/consolas/YaHei.Consolas.1.12.ttf
cd /usr/share/fonts/consolas
sudo mkfontscale && sudo mkfontdir && sudo fc-cache -fv
<?php
/**
* Quando precisamos pegar o access_token e token_secret.
*
* Precisamos ter a OAuth lib instalada no PHP, caso ela não esteja presente, no Ubuntu podemos instalar com:
* $ sudo apt install php-oauth
*/
function usage()
<?php
/**
* Quando precisamos pegar o request_token e o token_verifier.
*
* Precisamos ter a OAuth lib instalada no PHP, caso ela não esteja presente, no Ubuntu podemos instalar com:
* $ sudo apt install php-oauth
*/
function usage()
<?php
/**
* @see http://www.corporativo.correios.com.br/encomendas/sigepweb/doc/Manual_de_Implementacao_do_Web_Service_SIGEP_WEB.pdf
*/
// homologação
$soap = new \SoapClient('https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl', ['cache_wsdl' => WSDL_CACHE_NONE]);
// configs
$usuario = 'sigep';
<?php
/**
* Quando já temos o access_token e o token_secret.
*
* Precisamos ter a OAuth lib instalada no PHP, caso ela não esteja presente, no Ubuntu podemos instalar com:
* $ sudo apt install php-oauth
*/
$url = 'https://<mage-host>/api/rest/';