Caglar2306
Grünschnabel
Ich hätte eigentlich gedacht, dass PHP Step to Step arbeitet, aber komischerweiße werden erst die Daten an den TCP Server gesendet und erst dann der SQL Code ausgeführt bzw. während die SQL Abfrage am Laufen ist, wird es schon gesendet und ich bin verzweifelt..
Wenn ich das NON OOP mache, sprich eine Datei erstelle wo ich das selbe nur ohne Klassen versuche, funktioniert es jedoch einwandfrei (Arbeite mit namespaces).
Und die Klasse
Wenn ich das NON OOP mache, sprich eine Datei erstelle wo ich das selbe nur ohne Klassen versuche, funktioniert es jedoch einwandfrei (Arbeite mit namespaces).
PHP:
<?php
$alert = $this->getAlertManager()->getById(2);
if($alert->set('message', 'Hello world!')) {
$mus = new Mus('127.0.0.1', 4921);
$mus->send('update_alert_caches', [$alert->getRows()->id]);
}
PHP:
<?php
public function set(string $row, string $val) {
try {
$query = $this->getConnection()->prepare('UPDATE `' . $this->getTable() . '` SET `' . $row . '` = :val WHERE `id` = :id');
if($query->execute([':id' => $this->getRow()->id, ':val' => $val])) {
$this->updateRowByColumn('id', $this->getRow()->id);
return true;
} else {
return false;
}
} catch(PDOException $ex) {
echo $ex->getMessage();
} finally {
return $this;
}
}
Und die Klasse
PHP:
<?php
namespace Application\Helpers\Mus {
final class Mus {
private $socket = null;
private $connected = false;
private $ip, $port;
private $error;
public function __construct(string $ip, int $port) {
$this->socket = @socket_create(\AF_INET, \SOCK_STREAM, getprotobyname('tcp'));
$this->ip = $ip;
$this->port = $port;
$this->connect();
}
public function __destruct() {
@socket_close($this->socket);
}
public function connect() {
$this->connected = @socket_connect($this->socket, $this->ip, $this->port);
if(!$this->isConnected()) {
$this->error = socket_last_error();
if($this->error != 10035 && $this->error != \SOCKET_EINPROGRESS && $this->error != \SOCKET_EALREADY) {
@socket_close($this->socket);
}
}
}
public function isConnected(): bool {
return $this->connected;
}
public function send(string $header, array $data = []): bool {
if($this->isConnected()) {
$data = $header . chr(1) . implode(':', $data);
if(@socket_send($this->socket, $data, strlen($data), \MSG_DONTROUTE)) {
return true;
}
}
return false;
}
}
}